'Why bot doesn't fire messageReactionAdd event when the message was sent before the bot was online
This is my event to check user add react:
const client = require("../index");
client.on('messageReactionAdd', async (reaction, user) => {
if (user.bot) return;
console.log(reaction.emoji.name);
});
It's working, but when the bot restarts, it can't fetch any message sent before?
Why and how to fix it?
Solution 1:[1]
You need partials:
const client = new Client({
intents: ‘’, // your intents here
partials: ['CHANNEL', 'GUILD_MEMBER', 'GUILD_SCHEDULED_EVENT', 'MESSAGE', 'REACTION', 'USER'],
});
Solution 2:[2]
If you don't enable partial structures, your code only works on cached messages, ones posted after the bot is connected. Reacting on older messages won't fire the messageReactionAdd event. If you also want to listen to reactions on old messages you need to enable partial structures for MESSAGE, CHANNEL and REACTION when instantiating your client, like this:
const client = new Discord.Client({
intents: [/* YOUR INTENTS */],
partials: ['MESSAGE', 'CHANNEL', 'REACTION'],
});
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Gh0st |
| Solution 2 | Zsolt Meszaros |
