【问题标题】:How to check if a member can be kicked/banned in discord.js v12?如何检查成员是否可以在 discord.js v12 中被踢/禁止?
【发布时间】:2021-02-10 15:41:08
【问题描述】:

我创建了一个可以正常工作的禁止命令,除非你试图踢出比机器人更高角色的人。有没有一种简单的方法来检查用户是否可以被踢?我尝试检查客户端是否具有比此人更高的角色,但是当您尝试踢服务器的所有者(如果他没有角色)时它会失败。我的代码在这里:

        var User = message.guild.member(message.mentions.members.first()) || message.guild.members.cache.get(args[0]);
        if (!User) return message.reply("please mention the one who should be banned")
        if(User.id === message.author.id) {
            return message.reply('can not allow self-harm')
        };
        if (message.member.roles.highest.comparePositionTo(User.roles.highest) <= 0) {
            return message.reply('you can not ban a user with the same (or higher) permissions as you')
        };
        var banReason = args
        banReason.shift()
        banReason = banReason.toString()
        banReason = banReason.replace(/,/g, ' ')

        if (!banReason) {
            banReason = "No reason provided"
        };
        var banReason2 = `Banned by ${message.author.tag} -` + ' ' + banReason
        User.ban({reason: banReason2}).catch(error => {
            message.channel.send(`Failed to ban <@${User.id}>`)
            return console.log(error)
        })

        message.reply(`you have succesfully banned <@${User.id}> with the reason **${banReason}** <a:excitedwave:758043553573372117>`);

        const embed = new Discord.MessageEmbed()

        .setColor('#FF0000')
        .setTitle(`You have been banned from ${message.guild.name}`)
        .setDescription(`**Banned by:** <@${message.author.id}>\n**Ban reason:** ${banReason}`)
        .setTimestamp()

        User.user.send(embed).catch(error => {
            message.channel.send(`Failed to DM <@${User.id}> the info about this action`)
            console.log(error)
        })

提前致谢

【问题讨论】:

    标签: node.js discord.js


    【解决方案1】:

    您应该尝试使用bannablekickable 属性。 如果结果是FALSE,则不能踢或禁止用户。

    用法:

    mentionnedUser.bannable // Should return TRUE or FALSE
    mentionnedUser.kickable // Should return TRUE or FALSE
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-15
      • 1970-01-01
      • 2020-11-14
      • 2021-08-22
      • 2020-11-18
      • 1970-01-01
      • 2021-01-26
      • 1970-01-01
      相关资源
      最近更新 更多