'How to count amount of reactions in Discord.js v13?

I have tried so many things out, here's my current code

        var green = toString(msg.reactions.cache.get('🟩').count);
        var red = toString(msg.reactions.cache.get('🟥').count);
          
         msg.reply("Poll has ended which was created by " + msg.author.username)
         msg.reply(green + " " + red)

It gives this error

        var green = toString(msg.reactions.cache.get('🟩').count);
                                                          ^

TypeError: Cannot read properties of undefined (reading 'count')

Please help!

I want it to display how many people reacted on 🟩 and 🟥.

I'm not able to do that even after asking Discord.js experts, I can't understand how to get them.

I also want them to be a string, that's why I used The toString() function.

This is for a poll/vote bot I am making.

I react to the messages and still it shows this error.

This is Discord.js v13.

Thanks!

TheThiefingKing



Solution 1:[1]


let msg = await message.channel.messages.fetch("974311411314475059")
let reactsSize = msg.reactions.cache.get("?").count
message.channel.send("? Reacts on that message is: " + (+reactsSize))

You need to await message first after that you can fetch reactions.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Neenhila