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?
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
}
}
});
Thank you so much!!!
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!
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
Is client defined? do you have const client = new Discord.Client()
?
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?
do you have const Discord = require("discord.js")
?
It didn’t, but I just added it. Thanks!
guys i tried this and not working
client.on(‘messageReactionAdd’, (messageReaction, user) => {
const { message, emoji } = messageReaction;
if(emoji.name === “”) {
if(message.id === “msg id added”) {
message.channel.send(“cool”)
}}});
I think emoji.name
should be the name of the emoji and not the emoji itself.
like this
if(emoji.name === “”) {
or this
if(emoji.name === “smiley”) {
i tried both of them and added reaction to the msg and still dont work
This ^^^^^
You have to specify the name as what Discord says.
yes i took it from discord the name
Any errors in the logs?
Unicode emojis are considered to be just emoji
and not emoji.name
as Discord cannot provide much information about them.
so this code wont work? any other code similar please im new to coding and i need this
As I can see, your variables are not set correctly in the first line, it should be: reaction, user
Futhermore, you should have some like this in the fifth line of your given code.
if(emoji.name == "😄"){
//rest code goes here
I hope this helped you solve your problem.
the code work with this
client.on(‘messageReactionAdd’, (messageReaction, user) => {
const { message, emoji } = messageReaction;
if(emoji.name == ‘’) {
message.channel.send(“cool”)
}});
but it work on every msg the error was on if(message.id === “msg id added”) {
how to make it on specific msg other then this way
Try changing your variables to
reaction, user
not working with reaction,user even the one with no message.id
Which version of discord.js are you using?
i use version 11.5.1
is there way to do with channel id instate of message id i did message.channel.id=" id"
and didnt work
a message reaction is directly linked to the message itself, since you’re reacting on one specific message, are you sure you want to watch for reactions in the whole channel?