Javascript 尝试使用变量时出现Discord.js Ban错误
我想做一个机器人,让它有一个ban命令。没有理由的话,ban命令非常有效。但一旦我给它一个理由,它就会停止工作,并给我这个错误:Javascript 尝试使用变量时出现Discord.js Ban错误,javascript,node.js,variables,discord,discord.js,Javascript,Node.js,Variables,Discord,Discord.js,我想做一个机器人,让它有一个ban命令。没有理由的话,ban命令非常有效。但一旦我给它一个理由,它就会停止工作,并给我这个错误: {“title”:“为服务器投票!”,“description”:“我刚刚将服务器发布到top.gg,这是最大的服务器列表网站之一。请为服务器投票[此处](https://top.gg/servers/754062115123232938/vote)这样更多的人可以了解它。这将真正帮助服务器的发展。”,“color”:10426392,“footer”:{“text”
{“title”:“为服务器投票!”,“description”:“我刚刚将服务器发布到top.gg,这是最大的服务器列表网站之一。请为服务器投票[此处](https://top.gg/servers/754062115123232938/vote)这样更多的人可以了解它。这将真正帮助服务器的发展。”,“color”:10426392,“footer”:{“text”:“©红门,2020”}
如果您知道如何解决此问题,将不胜感激。以下是我当前禁止用户的代码:
if (message.member.roles.cache.some(role => role.name === config.modRole)) {
// Looks for the mentioned user
const user = message.mentions.users.first();
if(user){
// Checks if the user mentioned is in the server
const member = message.guild.member(user);
if(member){
// Bans the user
member.ban(config.banMessage).then(() =>{
message.reply(`sucessfuly banned ${user.tag}.`);
console.log(`Sucsessfuly banned ${user.tag} in ${message.guild}`)
}).catch(error =>{
// Catches any errors
message.reply(`I encountered an error when trying to ban ${user.tag}`);
console.log(`Error banning ${user.tag} in ${message.guild}`);
console.error(error);
})
} else {
message.reply(`That user isn\'t in the server.`)
}
} else {
message.reply(`you need to specify a valid user to ban!`)
}
} else {
message.reply('you do not have permission to use this command!')
console.log(`${message.author} tried to use the ban command in ${message.guild} but did not have sufficient permissions`)
}
},
发现了我的问题。ban命令使用原因的方法与kick命令不同。对于kick命令,您可以简单地使用message.author.kick(“原因”),如前所述。但是对于ban命令,您使用message.author.ban({reason:“reason”})。这不是错误,也没有使用“原因”“在你提供的代码中。我的错,我复制了错误的东西。我一到家就抄写正确的错误。