Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

123
Views
Discord.js not properly returning the amount of a certain reactions on a message

I am currently coding a discord bot with the discord.js library. I am currently adding poll command. The user will input something that looks like this

sh.poll (Amount of time the poll will stay open for) (The contents of the poll)

All the other code works fine, it can properly read the amount of time the user inputs and can read the text the poll is suposed to show. The problem arises when the poll has to close.

The bot will start by reading the reactions that are currently on the poll, then it will output if the poll succseeded or not. However command that I am using:

Message.reactions.cache.get('Unicode Charcter').count

It always returns 1.

I feel like there is something very simple I am missing but I just cant find it.

message.channel.send(message.content.slice(9 + message.content.split(' ')[1].length)).then(sent => { // Gets the message the user wants to send and sends it, also records the message ID in the sent var.
            message.delete(); // Deletes the original command message
            sent.react('๐Ÿ‘'); // Adds reactions to the message sent by the bot
            sent.react('๐Ÿ‘Ž'); // Adds reactions to the message sent by the bot

            setTimeout(function(){ // Waits an amount of time determined earlier in the code
                console.log(sent.reactions.cache.get('๐Ÿ‘').count); // This is the main command with the problem, always will print out 1 even if there are 2 or 3 reactions added
                
                }
            }, waitTime);
        })
client.on('messageCreate', message => {
    if (!message.content.startsWith(prefix) || message.author.bot) {
        return;
    }

    const args = message.content.slice(prefix.length).split(/ +/); // Takes out the prefix
    const command = args.shift().toLowerCase(); // Makes the text lowercase

    } else if (command.startsWith('poll')) { // If the message had the command poll
        client.commands.get('Poll').execute(message, args); // Executes the code shown above
about 4 years ago ยท Juan Pablo Isaza
1 answers
Answer question

0

Fetch the message once the poll as closed (once the timeout is executed) and then check the updated properties. I have included a code sample below:

setTimeout(async () => {

    const msg = await sent.fetch(true);
    console.log(msg.reactions.cache.get('๐Ÿ‘').count);

}, waitTime);
about 4 years ago ยท Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
ยฉ 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!