我创建了一个禁止命令,该命令可以正常工作,除非您尝试踢一个比机器人更高角色的人。有没有简单的方法可以检查用户是否可以被踢?我尝试检查客户端是否具有比该人员更高的角色,但是如果您尝试踢服务器的所有者(如果他没有角色),则会失败。我的代码在这里:
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)
})
预先感谢