我正在发出警告命令,但出现此错误:
cannot read property 'send' of undefined
我没有观看YT视频,而是由我自己执行命令,也不知道自己在做什么。我对编码和编码Discord机器人非常陌生,所以如果您能帮助我,那将会很棒
这是我的代码:
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;
}
});
如果我的代码还有其他问题,请告诉我
答案 0 :(得分:1)
last语句之一是message.person.send(`You have been warned from **${message.guild.name}** for ${arg}`)
。您正在访问已发送消息中的“人”,但是消息中不存在“人”(因此未定义)。您应该像之前定义的那样用message.person
替换person
。