如何比较用户角色?
How do I compare user roles?
我正在使用 discord.js 执行禁止命令,但我不知道如何检查目标角色是否低于执行命令的用户。我试图查找它,但我找不到它。我在其他 discord 机器人中看到过这个功能,所以任何帮助将不胜感激!
GuildMember 有 .highestRole
that returns the top role the member has. From there you can compare the position of both members highest roles and determine if one can ban each other. You can even use .comparePositionTo()
比较角色。
if(message.member.highestRole.comparePositionTo(message.mentions.members.first().highestRole) > 0){
//member has higher role then first mentioned member
message.mentions.members.first().ban();
}
(未测试)
我正在使用 discord.js 执行禁止命令,但我不知道如何检查目标角色是否低于执行命令的用户。我试图查找它,但我找不到它。我在其他 discord 机器人中看到过这个功能,所以任何帮助将不胜感激!
GuildMember 有 .highestRole
that returns the top role the member has. From there you can compare the position of both members highest roles and determine if one can ban each other. You can even use .comparePositionTo()
比较角色。
if(message.member.highestRole.comparePositionTo(message.mentions.members.first().highestRole) > 0){
//member has higher role then first mentioned member
message.mentions.members.first().ban();
}
(未测试)