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. 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.
Look in the guild's RoleManager for a role that does not have the permission by using .find()
. This will return the first role that does not have '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.
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'));
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.