Home > Mobile >  Why bot doesn't fire messageReactionAdd event when the message was sent before the bot was onli
Why bot doesn't fire messageReactionAdd event when the message was sent before the bot was onli

Time:04-21

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?

CodePudding user response:

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'],
});

CodePudding user response:

You need partials:

const client = new Client({
    intents: ‘’, // your intents here
    partials: ['CHANNEL', 'GUILD_MEMBER', 'GUILD_SCHEDULED_EVENT', 'MESSAGE', 'REACTION', 'USER'],
});
  • Related