Reputation: 35
I'am trying to code a discord bot with node.js, but i have a problem with messageReactionAdd I don't now why the bot does nothing when i react with an emoji.
My code :
bot.on('messageReactionRemove', (reaction, user) => {
console.log("that work 1");
if(reaction.emoji.name === "white_check_mark") {
console.log("that work 2");
}})
Upvotes: 2
Views: 27140
Reputation: 919
Update 2022. You may need to add intents for GUILD_MESSAGES
and GUILD_MESSAGE_REACTIONS
with cache messages to make it work.
Reference: https://discordjs.guide/popular-topics/reactions.html#listening-for-reactions-on-old-messages
const client = new Client({
intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS],
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
});
Upvotes: 8
Reputation: 3270
The message must be cached before it will work. Any messages that come in while your bot is open will automatically get cached, but if it's for a specific older message, you can use:
client.channels.get(CHANNELID).fetchMessage(MESSAGEID);
to cache it. After doing this (each time your script is run) you will receive reaction events for that message.
Upvotes: 2
Reputation: 6816
You should listen to the messageReactionAdd
event.
Keep also in mind that ReactionEmoji.name
is the Unicode for that emoji: you can get the Unicode symbol by writing a backslash before the emoji, like \:joy:
. The Unicode for :white_check_mark:
is ✅.
This should be your code:
bot.on('messageReactionAdd', (reaction, user) => {
console.log("first check");
if (reaction.emoji.name === "✅") {
console.log("second check");
}
});
This will work on every cached message, if you want it to work only on a specific message, try using Message.awaitReactions()
or Message.createReactionCollector()
Upvotes: 0
Reputation: 174
Events messageReactionAdd
and messageReactionRemove
working only for cached messages. You need add raw event to your code for trigger any message.
https://github.com/AnIdiotsGuide/discordjs-bot-guide/blob/master/coding-guides/raw-events.md
Upvotes: 11
Reputation: 1581
You are doing reaction remove and you need to use Unicode emojis - you can find these online and copy them
Upvotes: 0