【问题标题】:What is wrong with this Unban command这个 Unban 命令有什么问题
【发布时间】:2021-05-25 15:57:25
【问题描述】:

我尝试发出 Unban 命令,但是当我尝试使用用户的 id 来解除某人的禁令时,我的机器人并没有禁止他们,我不知道如何解决它。

代码:

module.exports = {
    name: 'unban',
    description: 'unban a member',
    async execute(bot, message, args, cmd, Discord) {
      let userID = args[0]
      let reason = args.slice(1).join(" ")

      if(!reason) reason = 'Unspecified'
      if(!args[0]) return message.reply("Please enter the ID of the user you want to unban.")
      if(!message.member.hasPermission(['BAN_MEMBERS', 'ADMINISTRATOR'])) return message.reply("You don't have the right permission to do that.")

      message.guild.fetchBans().then(async bans => {
        if(bans.size == 0) return message.reply("There are no Bans on this server")
        let bUser = bans.find(b => b.user.id);
        if(!bUser) return message.reply("The mentioned ID is not banned")
        message.guild.members.unban(bUser)
        message.reply("User unbanned!")
      })
    }
  }

错误:

(node:11908) UnhandledPromiseRejectionWarning: Error [BAN_RESOLVE_ID]: Couldn't resolve the user ID to unban.
at GuildMemberManager.unban (C:\Users\ADRIAN\Desktop\ZerOne BOT\node_modules\discord.js\src\managers\GuildMemberManager.js:243:36)

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    问题是 let bUser = bans.find(b => b.user.id) 返回它在该集合中找到的第一个用户,因为您不检查用户 ID 是否相同,您只检查被禁止用户上是否存在 b.user.id。它只是在第一个被禁止的用户上返回true。

    您应该检查 b.user.id === userID 是否改为:

    module.exports = {
        name: 'unban',
        description: 'unban a member',
        async execute(bot, message, args, cmd, Discord){
          let userID = args[0]
          let reason = args.slice(1).join(" ")
    
          if(!reason) reason = 'Unspecified'
          if(!userID) 
            return message.reply("Please enter the ID of the user you want to unban.")
          if(!message.member.hasPermission(['BAN_MEMBERS', 'ADMINISTRATOR'])) 
            return message.reply("You don't have the right permission to do that.")
    
          message.guild.fetchBans().then(async bans => {
            if(bans.size == 0) 
              return message.reply("There are no Bans on this server")
    
            let bUser = bans.find(banInfo => banInfo.user.id === userID);
    
            if(!bUser) 
              return message.reply("The mentioned ID is not banned")
    
            message.guild.members.unban(bUser.user.id)
            message.reply("User unbanned!")
          })
        }
      }
    

    【讨论】:

    • 它仍然给我同样的错误:(node:9308) UnhandledPromiseRejectionWarning: E​​rror [BAN_RESOLVE_ID]: Couldn't resolve the user ID to unban.
    • 啊,是的,因为bUser不是用户本身而是baninfo...应该是.unban(bUser.user.id)。
    猜你喜欢
    • 1970-01-01
    • 2018-01-25
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-18
    • 1970-01-01
    • 2022-07-21
    相关资源
    最近更新 更多