discord.ts icon indicating copy to clipboard operation
discord.ts copied to clipboard

"messageReactionAdd" listener is not triggered in old messages

Open ythepaut opened this issue 4 years ago • 2 comments

Hello, I encountered an issue when I tried to listen to user reactions on messages : A messageReactionAdd listener won't trigger if the message the reaction was added on was sent before the bot started.

Code where I ran my tests :

import {ArgsOf, On} from "@typeit/discord";

export abstract class Reaction {

    @On("messageReactionAdd")
    private async processEvent([reaction, user]: ArgsOf<"messageReactionAdd">) {
        console.log("**REACTION**", reaction.emoji.name);
    }
}

The console.log() is triggered on messages sent after the bot started, but not before.

ythepaut avatar Jul 06 '21 12:07 ythepaut

discord instance cache messages that sent after bot started. you can try to fetch previous messages then it might let you see reactions for old messages.

vijayymmeena avatar Jul 06 '21 14:07 vijayymmeena

This is how Discord.js behaves too. The raw event should still be passed though, so you should be able to do something like this (this is old discord.js code of mine, not adapted for discord.ts).

    client.on("raw", (ev) => {
        if (!ev.t || ev.t != "MESSAGE_REACTION_REMOVE") return;
   
        let messageId = ev.d.message_id;
        let emoji = ev.d.emoji.name;
    });

Cosmiiko avatar Jul 29 '21 13:07 Cosmiiko