本文介紹了錯誤 [BAN_RESOLVE_ID]:無法將用戶 ID 解析為解禁的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!
問題描述
我正在嘗試創(chuàng)建自己的 discord 機器人并現在創(chuàng)建一個 unban 命令.我的代碼如下.我禁止了一個朋友并嘗試通過輸入 -unban 271375814384287744 testing
來解禁.然后它給我一個錯誤說 Error [BAN_RESOLVE_ID]: Couldn't resolve the user ID to unban.
任何幫助將不勝感激.
I am trying to create my own discord bot and creating an unban command now. My code is below. I banned a friend and tried to unban by typing -unban 271375814384287744 testing
. It then gives me an error saying Error [BAN_RESOLVE_ID]: Couldn't resolve the user ID to unban.
Any help would be appreciated.
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);
}
}
}
推薦答案
我試過了,也遇到了同樣的錯誤.
I tried this out and got the same error.
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
<小時>事實證明,您應該只通過他們的 ID 而不是他們的用戶屬性來解禁這些人.因此,要取消禁止被禁止的成員,請改用以下代碼:
Turns out, you should just unban the people by their IDs instead of their user property. So, to unban the banned member use this code instead:
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);
}
}
}
這篇關于錯誤 [BAN_RESOLVE_ID]:無法將用戶 ID 解析為解禁的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!
【網站聲明】本站部分內容來源于互聯(lián)網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯(lián)系我們刪除處理,感謝您的支持!