我正在尝试创建自己的discord bot并现在创建一个unban命令。我的代码如下。我禁止了一个朋友,并尝试通过输入-unban 271375814384287744 testing
来取消禁止。然后,我看到一个错误,说Error [BAN_RESOLVE_ID]: Couldn't resolve the user ID to unban.
可以提供任何帮助。
const Discord = require('discord.js');
const client = new Discord.Client();
const embed = new Discord.MessageEmbed()
.setColor('#39de33')
module.exports = {
name: 'unban',
description: "This unbans a user",
execute(message, args){
if (message.member.permissions.has("BAN_MEMBERS")){
if (!isNaN(args[0])) {
const bannedMember = client.users.fetch(args[0]);
var reason = args.slice(1).join(" ");
if(!reason) {
reason = "No reason given!"
}
if (bannedMember) {
bannedMember
message.guild.members.unban(bannedMember, reason)
.then(() => {
embed.setDescription(`Successfully unbanned **${user.tag}**`);
message.channel.send(embed);
})
.catch(err => {
embed.setDescription('I was unable to unban the member');
message.channel.send(embed);
console.error(err);
});
} else {
embed.setDescription("That user isn't in this guild!");
message.channel.send(embed);
}
} else {
embed.setDescription("You need to provide an user ID to unban");
message.channel.send(embed);
}
} else {
embed.setDescription("You do not have `BAN_MEMBERS` permissions to unban this member");
message.channel.send(embed);
}
}
}
答案 0 :(得分:1)
我尝试了这个,并得到了相同的错误。
Promise {
<rejected> Error [BAN_RESOLVE_ID]: Couldn't resolve the user ID to unban.
at GuildMemberManager.unban (/home/kayuimineko/Arc-Neko/node_modules/discord.js/src/managers/GuildMemberManager.js:240:36)
at eval (eval at <anonymous> (/home/kayuimineko/Arc-Neko/cmdhandler/eval.js:49:26), <anonymous>:1:23)
at /home/kayuimineko/Arc-Neko/cmdhandler/eval.js:49:26
at /home/kayuimineko/Arc-Neko/node_modules/mongoose/lib/model.js:4838:16
at /home/kayuimineko/Arc-Neko/node_modules/mongoose/lib/model.js:4838:16
at /home/kayuimineko/Arc-Neko/node_modules/mongoose/lib/helpers/promiseOrCallback.js:24:16
at /home/kayuimineko/Arc-Neko/node_modules/mongoose/lib/model.js:4861:21
at /home/kayuimineko/Arc-Neko/node_modules/mongoose/lib/query.js:4407:11
at /home/kayuimineko/Arc-Neko/node_modules/kareem/index.js:135:16
at processTicksAndRejections (internal/process/task_queues.js:79:11) {
[Symbol(code)]: 'BAN_RESOLVE_ID'
}
}
正在运行
message.guild.members.unban(client.users.fetch(config.admin.owner.id), "reason")
// Ignore the config part it's fine
const Discord = require('discord.js');
const client = new Discord.Client();
const embed = new Discord.MessageEmbed()
.setColor('#39de33')
module.exports = {
name: 'unban',
description: "This unbans a user",
execute(message, args){
if (message.member.permissions.has("BAN_MEMBERS")){
if (!isNaN(args[0])) {
const bannedMember = message.guild.members.cache.get(args[0]) // Get the `member` property instead to recall later.
var reason = args.slice(1).join(" ");
if(!reason) {
reason = "No reason given!"
}
if (bannedMember) {
bannedMember
message.guild.members.unban(bannedMember.id, reason)
.then(() => {
embed.setDescription(`Successfully unbanned **${bannedMember.user.tag}**`); // `user` is undefined.
message.channel.send(embed);
})
.catch(err => {
embed.setDescription('I was unable to unban the member');
message.channel.send(embed);
console.error(err);
});
} else {
embed.setDescription("That user isn't in this guild!");
message.channel.send(embed);
}
} else {
embed.setDescription("You need to provide an user ID to unban");
message.channel.send(embed);
}
} else {
embed.setDescription("You do not have `BAN_MEMBERS` permissions to unban this member");
message.channel.send(embed);
}
}
}