错误 [BAN_RESOLVE_ID]:无法将用户 ID 解析为解禁

Posted

技术标签:

【中文标题】错误 [BAN_RESOLVE_ID]:无法将用户 ID 解析为解禁【英文标题】:Error [BAN_RESOLVE_ID]: Couldn't resolve the user ID to unban 【发布时间】:2020-12-21 20:43:18 【问题描述】:

我正在尝试创建自己的 discord 机器人并现在创建一个 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);
      
  

【问题讨论】:

可能会显示您传递的参数并检查传递的 ID 是否确实存在。错误消息似乎很清楚。 Discord 找不到要禁止的用户 ID 是的,我又试了一次,禁止我的一个朋友,并试图通过处理他的 ID 来解禁。它一直说“我无法解禁该成员” 【参考方案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

事实证明,您应该只通过他们的 ID 而不是他们的用户属性来解禁这些人。 因此,要取消禁止被禁止的成员,请改用以下代码:
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 解析为解禁的主要内容,如果未能解决你的问题,请参考以下文章

尝试将用户登录到 QBChat 时如何删除错误“无法识别的选择器”

Mailchimp 错误 400 请求,无法将用户发送到列表

错误:可写原子属性无法将合成的 setter/getter 与用户定义的 setter/getter 配对

MS Teams:无法按用户将应用程序添加到 MS Teams

如何修复:无法将关键字“用户”解析为字段。选项有:description、end_time、id、start_time、title Django 错误

knit2wp错误。无法识别用户名或密码