Incorrect reaction.count

I'm getting a reaction.count of 1 after receiving a reaction add event despite the message having 17 of these reactions. What can I do to troubleshoot this? I'm calling on partial reactions when needed, though that's not the case here.
17 Replies
d.js toolkit
d.js toolkit14mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
jr
jr14mo ago
Checking reaction.message.reactions.cache gives the same number Same with reaction.message.reactions.resolve I request most intents and all the partials that should be relevant
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildModeration,
Discord.GatewayIntentBits.GuildEmojisAndStickers,
Discord.GatewayIntentBits.GuildIntegrations,
Discord.GatewayIntentBits.GuildWebhooks,
Discord.GatewayIntentBits.GuildInvites,
Discord.GatewayIntentBits.GuildVoiceStates,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.GuildMessageReactions,
Discord.GatewayIntentBits.GuildMessageTyping,
Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.DirectMessages,
Discord.GatewayIntentBits.DirectMessageReactions,
Discord.GatewayIntentBits.DirectMessageTyping,
],
partials: [
Discord.Partials.Channel,
Discord.Partials.Message,
Discord.Partials.Reaction,
Discord.Partials.User,
],
intents: [
Discord.GatewayIntentBits.Guilds,
Discord.GatewayIntentBits.GuildMembers,
Discord.GatewayIntentBits.GuildModeration,
Discord.GatewayIntentBits.GuildEmojisAndStickers,
Discord.GatewayIntentBits.GuildIntegrations,
Discord.GatewayIntentBits.GuildWebhooks,
Discord.GatewayIntentBits.GuildInvites,
Discord.GatewayIntentBits.GuildVoiceStates,
Discord.GatewayIntentBits.GuildMessages,
Discord.GatewayIntentBits.GuildMessageReactions,
Discord.GatewayIntentBits.GuildMessageTyping,
Discord.GatewayIntentBits.MessageContent,
Discord.GatewayIntentBits.DirectMessages,
Discord.GatewayIntentBits.DirectMessageReactions,
Discord.GatewayIntentBits.DirectMessageTyping,
],
partials: [
Discord.Partials.Channel,
Discord.Partials.Message,
Discord.Partials.Reaction,
Discord.Partials.User,
],
Discord js seems to legit completely believe this message has 1 reaction, I am very confused Bump Updating from 14.8 to 14.10 didn't help
chewie 🌈
chewie 🌈14mo ago
Can you show a screenshot what number you mean exactly @jr.0
jr
jr14mo ago
Sure
jr
jr14mo ago
So if I add a star to this particular message in a discord server
chewie 🌈
chewie 🌈14mo ago
reaction.fetch() Resolve the promise and .count should be accurate
jr
jr14mo ago
jr
jr14mo ago
Is reaction.fetch() needed even when the reaction is not partial?
chewie 🌈
chewie 🌈14mo ago
No idea but its worth a try After restarting your bot to test it, its always partial Thats why the guide tells you to fetch the message and the reaction
jr
jr14mo ago
jr
jr14mo ago
So after calling .fetch, even when not partial, djs still thinks it has a count of 1 When my bot starts I'm fetching the first couple hundred messages in the channel to get them into the cache, otherwise it would be partial when the bot first starts up
chewie 🌈
chewie 🌈14mo ago
Can you show your code
jr
jr14mo ago
Yeah
override async on_reaction_add(
reaction: Discord.MessageReaction | Discord.PartialMessageReaction,
user: Discord.User | Discord.PartialUser
) {
if(!await this.is_valid_channel(reaction.message.channel)) {
return;
}
M.info(reaction.partial);
if(reaction.partial || true) {
M.info("DEPARTIALIZING REACTION");
reaction = await reaction.fetch();
}
//reaction.message.reactions.
M.log(
reaction,
reaction.count,
reaction.message.reactions.cache.get(reaction.emoji.name ?? "")?.count,
reaction.message.reactions.resolve(reaction.emoji.name ?? "")?.count,
reaction.message.url,
user.tag
);

// ... go and do other stuff
}
override async on_reaction_add(
reaction: Discord.MessageReaction | Discord.PartialMessageReaction,
user: Discord.User | Discord.PartialUser
) {
if(!await this.is_valid_channel(reaction.message.channel)) {
return;
}
M.info(reaction.partial);
if(reaction.partial || true) {
M.info("DEPARTIALIZING REACTION");
reaction = await reaction.fetch();
}
//reaction.message.reactions.
M.log(
reaction,
reaction.count,
reaction.message.reactions.cache.get(reaction.emoji.name ?? "")?.count,
reaction.message.reactions.resolve(reaction.emoji.name ?? "")?.count,
reaction.message.url,
user.tag
);

// ... go and do other stuff
}
And that's just attached to the messageReactionAdd event This doesn't happen for most messages It just seems there's a couple messages that are somehow haunted
chewie 🌈
chewie 🌈14mo ago
Cant reproduce any of this
jr
jr14mo ago
😅 I almost can't either, it works perfect 99.9% of the time
chewie 🌈
chewie 🌈14mo ago
What about reaction.users.cache.size
jr
jr14mo ago
Looks like that is also 1 Ok... I reacted from my phone instead of desktop and somehow the bot got the correct count I am so confused Ah and I reboot it and it's back to 1. If I spam the reaction eventually it gets the correct number though Could it be a bug on discord's end?