#Help with DiscordMessage.Reactions

1 messages · Page 1 of 1 (latest)

pulsar cove
#

Currently I am working on a new Discord bot, specifically within the MessageReactionAdded Event Handler. I am trying to look at all of the reactions on a message whenever a new one is added.

The wording of the DiscordMessage.Reactions field is "gets reactions used on this message" and it returns a read only list of DiscordReaction objects. From all of the testing I have done so far, it seems to only return one single react every time, regardless of the number of reactions on a message.

I am using the following code to test:

private static async Task OnReactionAdded(DiscordClient sender, MessageReactionAddEventArgs args)
{
    var message = args.Message;

    Console.WriteLine($"Total message reactions {message.Reactions.Count}");
    foreach (DiscordReaction reaction in message.Reactions)
    {
        Console.WriteLine($":{reaction.Emoji.Name}: was reacted by {reaction.Count} users!");
    }
    Console.WriteLine("--------------------------------------------------------------------");
}

Adding a new reaction to an empty message (expect 1, 1)

Adding a new reaction to a message with one reaction already (expect 2, 1 1)

Adding a second reaction to a message with one reaction already (expect 1, 2)

Adding a second reaction to a message with two reactions already (expect 2, 2 2)

Every output is the same: https://hst.sh/xatadiyuya.md

My question is, if the MessageReactionAddEventArgs includes the DiscordMessage object, why does it not also include the other reactions that were there before this new event? It seems as though it only includes the reaction from the event itself. Thanks in advance for the help!

hearty urchin
#

This looks like a error in our message caching, i will look into it. just to be sure: Youre using the latest nightly?

#

This is a cache issue, the message is not in cache so we dont have the correct state and construct a message from the event data

#

if the message is in cache it works correctly

pulsar cove
#

Gotcha, really appreciate the insight and investigation. Should I be trying to cache messages on my bot's end as a workaround then?

Right now I am using v4.5.0 of DSharpPlus

hearty urchin
#

The client caches messages wehn it recieves some in events, this error wont really happen in production when the reactions are on fairly new messages

#

i kinda forget how we cached in 4.5 but in nightlies the cache is 1 day after last access

pulsar cove
#

Hmm, that's likely the issue then. I was doing testing and making changes, so it likely didn't have any of that information cached for reach of the messages since the client was only live for a couple minutes

#

So all of the messages were "new" from the client's perspective

#

I wasn't sure if it was a caching thing, or if there was some kind of API call that would be able to just gather all of the reacts on a specific message at any time

tardy spear
hearty urchin