owengombas / discord.ts

🤖 Create your discord bot by using TypeScript and decorators!

Home Page:https://owencalvin.github.io/discord.ts/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

"messageReactionAdd" listener is not triggered in old messages

ythepaut opened this issue · 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.

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.

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;
    });