这是我为ban命令编写的代码
Crashbot.on('message', message => {
//looks for args if the user types a message with the defined prefix
let args = message.content.substring(PREFIX.length).split(" ");
//the switch equals true if the first arg (word) after the defined prefix is "ban"
switch (args[0]) {
case 'ban':
//checks if the message author has the needed permission to ban members
if (message.member.hasPermission('BAN_MEMBERS')) {
//checks if a user was mentioned to be banned and if not says that you need to specify someone to ban
if (!args[1]) message.channel.send('You need to specify a person !');
//makes a constant called user and sets it to the first person mentioned in the message
const user = message.mentions.users.first();
//checks if the constant "user" is a user mention
if (user) {
const member = message.guild.member(user);
//checks if the mentioned user is a member of the guild (the discord server)
if (member) {
//checks if there was anything typed after the user mention (second arg) if not bans the mentioned user and responds with successfully banned "user"
if (!args[2]) {
member.ban("Banned by Crashbot").then(() => {
message.reply(`Successfully banned ${user.tag}`);
}).catch(err => {
message.reply('I was unable to ban that member');
console.log(err);
});
//checks if there was anything typed after the user mention (second arg) and if there was ban the user and responds with successfully banned "user" for "reason specified in second arg"
}
else if (args[2]) {
member.ban(`${args[2]}`).then(() => {
message.reply(`Successfully banned ${user.tag} for ${args[2]}`);
}).catch(err => {
message.reply('I was unable to ban that member');
console.log(err);
});
}
}
}
}
break;
}
});
这是我不断进入控制台的错误
Response: Internal Server Error
at RequestHandler.execute (C:\Users\Michael\desktop\crashbot\node_modules\discord.js\src\rest\RequestHandler.js:158:11)
at processTicksAndRejections (internal/process/task_queues.js:97:5) {
code: 500,
method: 'put',
path: '/guilds/555146022490341476/bans/615261605860737035'
}
机器人不会崩溃,并且代码返回错误并继续按预期运行,但我不明白为什么我会不断收到此错误
答案 0 :(得分:-1)
您可以尝试放置完整的选项吗? (我不确定是否会成功,但让我们尝试一下)
// ban a guild member
guildMember.ban({ days: 7, reason: 'They deserved it' })
.then(console.log)
.catch(console.error);