Discord.NET Get Reactioncount of specific Reaction

Viewed 163

I want to count the number of reactions of a specific emoji everytime someone (except the bot ofcourse) adds a reaction to the message.

So this is what I have currently:

public async Task InitializeAsync()
{
    _client.ReactionAdded += HandleReactionAsync;
}
private async Task HandleReactionAsync(Cacheable<IUserMessage, ulong> message, Cacheable<IMessageChannel, ulong> channel, SocketReaction reaction)
{
    if (_client.GetUser(reaction.UserId).IsBot) return;
    
    if (reaction.Emote.Name == "")
    {
        int reactionCount = ?
        Console.WriteLine(reactionCount.ToString());
    }
}

So in the case that the bot reacts the program jumps out. (That works btw)

I just don't know how I would count the emotes. Does anyone know how I would do that? I couldn't find anything helpfull elsewhere (or perhaps the internet was simply mean to me). Thanks in advance :D

_

Edit:

The solution was as stated in the answer below. But to get the message in my case I needed to download it to the cache first:

private async Task HandleReactionAsync(Cacheable<IUserMessage, ulong> message, Cacheable<IMessageChannel, ulong> channel, SocketReaction reaction)
{
    if (_client.GetUser(reaction.UserId).IsBot) return;
    
    if (reaction.Emote.Name == "")
    {
        var emotes = await message.GetOrDownloadAsync().Result.GetReactionUsersAsync(new Emoji(""), 1000).FlattenAsync();
        int reactionCount = emotes.Count();
        Console.WriteLine(reactionCount.ToString());
    }
}
1 Answers

You can use the following to obtain it where message is the variable name for the message in your current context. (docs)

var emotes = await message.GetReactionUsersAsync(new Emoji("\U0001f495"), 1000).FlattenAsync();
int emotescount = emotes.Count();
Related