【问题标题】:Cannot read property 'send' of undefined discord.js warn command无法读取未定义 discord.js 警告命令的属性“发送”
【发布时间】:2020-12-15 22:54:43
【问题描述】:

我正在发出警告命令并收到此错误:

cannot read property 'send' of undefined

我没有关注 YT 视频,我是自己发出命令,但我不知道自己在做什么。我对不和谐机器人的编码和编码非常陌生,所以如果你能帮助我,那就太好了

这是我的代码:

bot.on('message', message => {
    if (!message.content.startsWith(PREFIX)) return;
    let args = message.content.substring(PREFIX.length).split(' ');
    if (message.author.bot) return;

    switch (args[0]) {
        case 'warn':
            if (message.channel.type === 'dm') {
                return message.reply('I can\'t execute that command inside DMs!');
            }
            const person = message.mentions.members.first();

            if (!person) return message.reply("Please mention a user");
            if (!message.author.hasPermission('MANAGE_MESSAGES'))
                return message.reply("You don't have permissions to warn members");
            var arg = message.cleanContent.split(" ").slice(2).join(" ")
            if(!arg) message.channel.send('Why are you warning the user for?')
            
            
                message.person.send(`You have been warned from **${message.guild.name}** for ${arg}`)
            
            break;


    }


});

另外,如果我的代码有什么问题,请告诉我

【问题讨论】:

    标签: javascript discord discord.js bots


    【解决方案1】:

    最后一个语句是message.person.send(`You have been warned from **${message.guild.name}** for ${arg}`)。您正在发送消息中访问“人”,但消息中不存在“人”(因此未定义)。您应该将 message.person 替换为 person,就像您之前定义的那样。

    【讨论】:

      猜你喜欢
      • 2021-04-16
      • 2020-06-05
      • 2021-04-26
      • 1970-01-01
      • 2020-06-17
      • 2018-12-01
      • 2021-11-02
      • 1970-01-01
      • 2021-04-12
      相关资源
      最近更新 更多