[Fixed] Message Reactions

I’m making a JavaScript Discord bot, how do I do something when someone reacts to a certain emoji on a message? Please may I have some code?

1 Like

This is a nice tutorial on how to make a basic reaction collector and await reactions

Tell us if you have a problem with it

I looked at that. How would I make it so the bot doesn’t trigger the code when it reacts?

Can you please explain what you’re wanting more? From what I understand, you want an event to be fired when someone reacts, but don’t want it to execute code.

no he wants the bot to react with all the reactions you can use to trigger but the but wouuld end up firing the code when it does

Hey there,
You may know Node.js events.
So, here’s what we are gonna do: the event messageReactionAdd triggers whenever someone reacts to a message. We’l; use that event to get the data required.
Example:

client.on('messageReactionAdd', (reaction, user) => {
// wallah!
// you can now access the property and methods of reaction as well as the user reacted on the message.
});

Cheers, for further queries feel free to mention me!

In that case, you would need to have the code block out bot accounts. Here’s an example:

client.on('messageReactionAdd', function(reaction, user) {
    if (!user.bot) {
        //The following code will only run if the user is not a bot, therefore filering out the initial bot reactions.
        console.log(reaction);
    }
});

Hope this answered your question!

How do I check for a specific emoji?

Basically, I’m making a help menu on a channel. So if a certain reaction is clicked, a channel is created. If another reaction is clicked, a message will send.

I do something like this for doing something for specific emojis:

	const { message, emoji } = messageReaction;
if(emoji.name === "the emoji here") {
// code to run when that emoji is reacted to on a message
}

How does it know what message to look for?

If you want it to be a specific message do this:

client.on('messageReactionAdd', (messageReaction, user) => {
if(user.bot)  return;
const { message, emoji } = messageReaction;

if(emoji.name === "the emoji here") {
if(message.id === "message id here") {
// code to run when that emoji is reacted on specified message
  }
 } 
});
1 Like

Thank you so much!!!

2 Likes

Yeah I’m a year or something late but how can you get the message ID

Welcome to the community! You can get the message ID by enabling Developer Mode in your Discord settings. A tutorial on fetching message IDs can be found here:

Hope this helps!

Screenshot 2020-04-01 at 7.30.18 PM

Can someone help me with this? I copied the code above and it isn’t working.

(I am attempting to make my own bot that is very similar to reaction roles bot, can someone give some code that could possibly do that?)

-Thanks,
TMD

@Callum-OKane

Is client defined? do you have const client = new Discord.Client()?

1 Like

Yes, now it says Discord is undefined?
I’m very new to coding, I only know how to do certain things. Is this something I missed in the beginning?

@MrDiamond64

do you have const Discord = require("discord.js")?

1 Like

It didn’t, but I just added it. Thanks!