Home > front end >  How to check if a specific user reacted with a specific emoji?
How to check if a specific user reacted with a specific emoji?

Time:10-05

I was trying to make it so that a user can only react once on a message.

This is my attempt

if(reaction.users.cache.has(user.id)) {
  reaction.remove().catch(err => {return;})
}

This always removes the reaction (I understand it's because the user just reacted). I tried checking the reaction emojis like this:

reaction.message.reactions.cache.some(r => r.emoji.name === 'my_emoji')

This always returns true because my bot reacts to it, and other people can also react.

I tried checking the docs but there is nothing like MessageReaction.user that could help.

How can I check if the specific user reacted with a specific emoji?

CodePudding user response:

Try accessing ReactionUserManager along with ReactionEmoji and check if the manager has the id and the current reaction's emoji is your target emoji.

reaction.message.reactions.cache
   .filter(r => r.emoji.name === 'my_emoji')
   .some(r => r.users.cache.has(user.id));
  • Related