简体   繁体   English

Discord.js | 我正在尝试检查角色是否具有静音角色的特定权限

[英]Discord.js | I'm trying to check if a role has a specific permission for a mute role

Basically I'm making a ultra customizable discord bot, and you have to specify in the config file the name of the role you want to use when you mute someone.基本上我正在制作一个超可定制的 discord 机器人,你必须在配置文件中指定当你静音某人时要使用的角色的名称。 And as a fail-safe in case the role is invalid or misspelled the bot looks himself for a role that has the permission "SEND_MESSAGE" turned off.如果角色无效或拼写错误,作为故障安全措施,机器人会自行查找已关闭“SEND_MESSAGE”权限的角色。

Look in the guild's RoleManager for a role that does not have the permission by using .find() .使用.find()在公会的RoleManager中查找没有权限的角色。 This will return the first role that does not have 'SEND_MESSAGES'这将返回第一个没有'SEND_MESSAGES'角色

const role = message.guild.roles.cache
   .find(r => !r.permissions.has('SEND_MESSAGES'));

role will return undefined if a role without 'SEND_PERMISSIONS' was not found.如果未找到没有'SEND_PERMISSIONS'的角色,则role将返回undefined

If you want to increase accuracy of finding a muted role given that the name is misspelled check what the name of the role starts with.如果您想在名称拼写错误的情况下提高查找静音角色的准确性,请检查角色名称的开头。

// Account for spelling mistakes, given that "mu" in "muted" is correct
const role = message.guild.roles.cache
   .find(r => !r.permissions.has('SEND_MESSAGES') && r.name.toLowerCase().startsWith('mu'));

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM