如果作者尝试,我该如何使我的机器人不接受消息作者highest role
?
我尝试使用if(message.member.roles.highest.position = gRole.position)
,但是没有用。
我的代码:
if (!message.member.hasPermission("MANAGE_ROLES")) return message.channel.send("You don't have permissions to use this!"); let member = message.mentions.members.first() if(!member) return message.channel.send("You must mention a user to assign/remove roles to/from") if(message.member.roles.highest.position < member.roles.highest.position) return message.channel.send("You cannot assign/remove roles of someone with a role higher than you") let role = args[2] if(!role) return message.channel.send("Provide a role name to assign/remove") let gRole = message.guild.roles.cache.find(r => r.name.toLowerCase() === role.toLowerCase()) if(message.member.roles.highest.position < gRole.position) { message.channel.send("That role is above your highest role, it can't be managed") } else { } if(!gRole) return message.channel.send(`The role \`${role}\` could not be found`) if(message.member.roles.highest.position > gRole.position) { if(!member.roles.cache.has(gRole.id)) { await member.roles.add(gRole.id) message.channel.send(`The role \`${role}\` has been added to **${member.user.username}**`) } else { await member.roles.remove(gRole.id) message.channel.send(`The role \`${role}\` has been removed from **${member.user.username}**`) } } } module.exports.help = { name: "role" }
答案 0 :(得分:1)
尝试if (message.member.roles.highest.position === gRole.position)
。
单个=
用于定义变量。为了比较值,您应该使用==
或===
。