猿问

TypeError:无法读取未定义的属性“hasPermission”

我正在制作一个不和谐的机器人,我主要学习了 discord.js 的 v11,当我在不和谐中创建一个 unban 命令时,当我完成时,我运行了该命令,它给出了错误“TypeError:无法读取属性” hasPermission' of undefined",这是我的代码。顺便说一句,它是一个命令处理程序


module.exports = {

    name : 'unban',

    execute(client, message, args){

       if(!message.member.hasPermission(["BAN_MEMBERS"])) return message.channel.send("You dont have permission to perform this command!")

    if(isNaN(args[0])) return message.channel.send("You need to provide an ID.")

    let bannedMember =  client.users.fetch(args[0])

        if(!bannedMember) return message.channel.send("Please provide a user id to unban someone!")


    let reason = args.slice(1).join(" ")

        if(!reason) reason = "No reason given!"


    if(!message.guild.me.hasPermission(["BAN_MEMBERS"])) return message.channel.send("I dont have permission to perform this command!")|

    message.delete()

    try {

        message.guild.members.unban(bannedMember, reason)

        message.channel.send(`**${bannedMember.tag}** has been unbanned from the guild!`)

    } catch(e) {

        console.log(e.message)

    }

}





No idea what the problem is.


缥缈止盈
浏览 159回答 1
1回答

ibeautiful

它看起来像message.guild.me.hasPermission并且message.member.hasPermission都是有效的方法。您确定message变量已定义吗?检查您的命令处理程序。
随时随地看视频慕课网APP

相关分类

JavaScript
我要回答