Home > OS >  Is there a way to listen for reaction events on a specific Discord message id
Is there a way to listen for reaction events on a specific Discord message id

Time:05-30

Let's say Person A has sent a message, with message ID "A1". How can I make my Bot listen to messageReactionAdd and messageReactionRemove events on that message, "A1"?

CodePudding user response:

You can use a Collector. message.createReactionCollector({ ... })

You can read more about Collectors here: https://discordjs.guide/popular-topics/collectors.html

Edit (comments)

If the message id is not changing, you can just return from your listener if the id of the reacttion's message isn't what you want.

Example:

client.on('messageReactionAdd', (reaction) => {
  if (reaction.message.id !== 'A1') return
  // Your code ...
})
client.on('messageReactionRemove', (reaction) => {
  if (reaction.message.id !== 'A1') return
  // Your code ...
})

Client emits a MessageReaction. you can get it's message using MessageReaction.message and you can get it's id using Message.id, which you compare to 'A1'.

If it's not equal to 'A1' you can return from the listener early using return keyword (so if the condition is true, you don't execute any more code in that function)

  • Related