Skip to content
Advertisement

Discord JS add role by reaction command doesn’t work after restart

I’m trying to make a “add role by reaction” command. So when a member reacts to a specific message, the member gets a role. It actually works but when I restart my bot, it doesn’t add a role anymore. Can anyone help?

here the code:

JavaScript

Advertisement

Answer

To make your bot check if previous messages have been reacted upon you could use a code similar to this

JavaScript

You might want to make some changes, but this works.

To break it down…

  1. Get messages in a specific channel (or multiple)
  2. Check if the message has reactions
  3. Check if any of the reactions match a specific emoji
  4. Add the role to the guild member
  5. Optionally check if the member already has the role before attempted to add it

Please note that this code might very well not be the most efficient, but it gets the job done. Also, it does NOT work with “non-custom” emojis, for that you’ll have to check for emoji.name instead of emoji.id.

As suggested by @michael.grigoryan it is very recommended to check out the documentation.

Edit: Removed previous answer, to remove confusion

Advertisement