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