Discord.js在尝试使用变量时出现Ban错误



我试图制作一个机器人程序,并让它有一个ban命令。毫无理由,ban命令非常有效。但一旦我给了它一个理由,它就会停止工作,并给我这个错误:{"title":"Go Vote for the Server!","description":"I've just finished posting the server to top.gg, one of the largest server listing sites. Please go vote for the server [here](https://top.gg/servers/754062115123232938/vote) so that more people can learn about it. It would really help the server grow. ","color":10426392,"footer":{"text":"© The Red Door, 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`)
}
},

发现我的问题。与kick命令相比,ban命令有一种不同的使用原因的方法。对于kick命令,您可以简单地使用message.auther.kick("reason"(。但是对于ban命令,您可以使用message.author.ban({reason:"reason"}(。

最新更新