Javascript “错误”;未捕获类型错误:无法读取属性';bannable';“未定义”的定义;

Javascript “错误”;未捕获类型错误:无法读取属性';bannable';“未定义”的定义;,javascript,node.js,discord,discord.js,Javascript,Node.js,Discord,Discord.js,你好,我正在开发我的discord机器人,我的ban命令出错 这是我为禁令写的代码 if (message.content.startsWith(prefix + "ban")){ let mention = message.mentions.members.first(); if (mention = undefined){ message.reply("Member

你好,我正在开发我的discord机器人,我的ban命令出错

这是我为禁令写的代码

        if (message.content.startsWith(prefix + "ban")){
            let mention = message.mentions.members.first();

            if (mention = undefined){
                message.reply("Member not mentionned");
            }
            else {
                if(mention.bannable){
                    mention.ban();
                    message.channel.send(mention + " was banned");
                }
                else {
                    message.reply("Impossible to ban this member");
                }
            }
        }
    }



JS使用
=
分配值,使用
=
检查值或
==
检查值并键入:

if (mention == undefined)
    message.reply("Member not mentionned");
或者您可以使用
未定义的
是错误的,因此:

如果
提及
,也可以这样做

由于您没有重新分配
提及
,我还建议您使用
常量
,因为您会得到一个错误:

const mention = message.mentions.members.first();

if (mention = undefined){ <-- now error throws here
const-title=message.indications.members.first();

如果(提及=未定义){您应该使用
提及===未定义
,而不是仅使用一个
=
(赋值)


JS正在抛出此错误,因为它无法在
中找到属性
bannable
,当它未定义时,因为空检查不正确。

您得到的错误是什么?@FluxedScript它在标题中:
“未捕获类型错误:无法读取未定义的属性'bannable'
const mention = message.mentions.members.first();

if (mention = undefined){ <-- now error throws here