discordjs / discord.js

A powerful JavaScript library for interacting with the Discord API
https://discord.js.org
Apache License 2.0
25.36k stars 3.97k forks source link

Bug: messageReactionRemove not triggering on uncached messages even with Partials #6662

Closed Amgelo563 closed 3 years ago

Amgelo563 commented 3 years ago

Issue description

The messageReactionRemove event doesn't seem to trigger at all on non cached messages even with Partials.

Weirdly enough the exact same code does work as intended with messageReactionAdd, I can react to messages older than the bot's age and it'll log it after caching it using Partials, but it doesn't work at all with messageReactionRemove. It only works on messages that are sent after the bot booted up or messages that messageReactionAdd fetched into cache.

Codesample

// Notice that this is an (almost, only removed the last console.log) exact copy of the example code on https://discordjs.guide/popular-topics/reactions.html#listening-for-reactions-on-old-messages, just using messageReactionRemove instead of messageReactionAdd

const { Client, Intents } = require('discord.js');

const client = new Client({
    intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES, Intents.FLAGS.GUILD_MESSAGE_REACTIONS],
    partials: ["MESSAGE", "CHANNEL", "REACTION"]
});
client.login("token");
console.log("Ready");

// This will trigger on cached messages, never on non cached messages
client.on('messageReactionRemove', async (reaction, user) => {
    if (reaction.partial) {
        try {
            await reaction.fetch();
        } catch (error) {
            console.error('Something went wrong when fetching the message:', error);
            return;
        }
    }
    console.log("Hello world I've been triggered");
});

discord.js version

discord.js@13.1.0

Node.js version

v16.9.0

Operating system

Windows

Priority this issue should have

Medium (should be fixed soon)

Which partials do you have configured?

CHANNEL, MESSAGE, REACTION

Which gateway intents are you subscribing to?

GUILDS, GUILD_MESSAGES, GUILD_MESSAGE_REACTIONS

I have tested this issue on a development release

No response

Jiralite commented 3 years ago

You will also need the USER partial. The reason why this works in Client#messageReactionAdd is because Discord sends the user object, but only sends the id of the user in Client#messageReactionRemove (discord.js attempts to resolve a user object, and stops if it cannot).

Amgelo563 commented 3 years ago

Thanks, after adding the USER partial it worked. Is this officially documented anywhere? I spent a really long while searching and could not find any documentation which lead me to think it was a bug, I apologize if it's documented though.

DTrombett commented 3 years ago

It's just logic. That event pass two parameters: a User and a MessageReaction object so both can be uncached and, in order for the event to be triggered, you need to enable both partials!