Bot not reading the correct number of reactions on a message (reads only 1)

The bot with a [given] message ID counts the number of upvotes and downvotes on a message, but for some reason keeps detecting only 1 of each reaction.
//Collect Emojis/Reactions
let x = 0;
let messageReacted;
for (let msgID of UpvoteContainer.msgID){
x = 0;
//fetch message(s) of ID UpvoteContainer.msgID
messageReacted = await interaction.client.channels.cache.get(interaction.channelId).messages.fetch(msgID);
//For Each Reaction on the message(s)
messageReacted.reactions.cache.forEach(async(reaction) => {
console.log("===================================");
console.log(`emojiName = ${reaction.emoji.name}`);
console.log(`emojiCount = ${reaction.count}`);
const reactionUsers = await reaction.users.fetch();
console.log(`reactionUsers = ${reactionUsers}`);
//const emojiName = reaction.emoji.name;
//const emojiCount = reaction.count
//const reactionUsers = await reaction.users.fetch();
if (reaction.emoji.id == UpvoteContainer.emojiUpvoteID){
console.log(color.GREEN + "Upvotes by " + reaction.count.toString() + color.RESET);
x = x + reaction.count;
}
else if (reaction.emoji.id == UpvoteContainer.emojiDownvoteID){
console.log(color.GREEN + "Downvotes by " + reaction.count.toString() + color.RESET);
x = x - reaction.count;
}
});
console.log(color.GREEN + "UpvoteContainer.msgUpvoteCount.push(x): " + x.toString() + color.RESET);
UpvoteContainer.msgUpvoteCount.push(x);
}
//Collect Emojis/Reactions
let x = 0;
let messageReacted;
for (let msgID of UpvoteContainer.msgID){
x = 0;
//fetch message(s) of ID UpvoteContainer.msgID
messageReacted = await interaction.client.channels.cache.get(interaction.channelId).messages.fetch(msgID);
//For Each Reaction on the message(s)
messageReacted.reactions.cache.forEach(async(reaction) => {
console.log("===================================");
console.log(`emojiName = ${reaction.emoji.name}`);
console.log(`emojiCount = ${reaction.count}`);
const reactionUsers = await reaction.users.fetch();
console.log(`reactionUsers = ${reactionUsers}`);
//const emojiName = reaction.emoji.name;
//const emojiCount = reaction.count
//const reactionUsers = await reaction.users.fetch();
if (reaction.emoji.id == UpvoteContainer.emojiUpvoteID){
console.log(color.GREEN + "Upvotes by " + reaction.count.toString() + color.RESET);
x = x + reaction.count;
}
else if (reaction.emoji.id == UpvoteContainer.emojiDownvoteID){
console.log(color.GREEN + "Downvotes by " + reaction.count.toString() + color.RESET);
x = x - reaction.count;
}
});
console.log(color.GREEN + "UpvoteContainer.msgUpvoteCount.push(x): " + x.toString() + color.RESET);
UpvoteContainer.msgUpvoteCount.push(x);
}
No description
2 Replies
d.js toolkit
d.js toolkit2w ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
Dismissed
Dismissed2w ago
console log output:
===================================
emojiName = Arrowup
emojiCount = 1
===================================
emojiName = Arrowdown
emojiCount = 1
UpvoteContainer.msgUpvoteCount.push(x): 0
===================================
emojiName = Arrowup
emojiCount = 1
===================================
emojiName = Arrowdown
emojiCount = 1
UpvoteContainer.msgUpvoteCount.push(x): 0
As can be seen in the screenshot, there should be 2 "Arrowup" reactions not 1 That worked, thanks. I'm surprised it didn't throw any "error" or so tho smh