Reputation: 33
I want to make the command work only if the user who reacts has a specific role or permission
I know I should use a filter but, I don't know-how this is the filter that I use
const approveFilter = (reaction, user) => reaction.emoji.name === '✅' ;
Upvotes: 0
Views: 285
Reputation: 8412
To check if a user has a role, you can use the GuildMemberRoleManager.cache
collection. To check if the user has a permission, you can use the GuildMember.hasPermission()
method.
Both of these require a GuildMember
object, although the filter
function passes a User
as the parameter (please see this post to learn the difference). So, the first step will be to convert the User
to a GuildMember
using the Guild.member()
function.
Luckily, we can access the guild object from the reaction
parameter!
const approveFilter = (reaction, user) =>
reaction.emoji.name === '✅' && // check emoji name
reaction.message.guild.member(user).roles.cache.has('Role ID') && // check if they have a role
reaction.message.guild.member(user).hasPermission('Permission Flag'); // check if they have a permission
Upvotes: 1