Reaction Collector not getting the correct size (capped at 1)

discord.js: 14.15.3 nodejs: v18.16.0 My intents are: Guilds GuildMessages GuildMessageReactions I'm using a reaction collector. Any time I print the collected.size, it returns 1 despite the filter showing multiple users reacting.
const filter = (reaction, user) => {
const userMember = guild.members.cache.get(user.id)
console.log(reaction.emoji.name === '🔑' && userMember.roles.cache.has(modRoleId))
return reaction.emoji.name === '🔑' && userMember.roles.cache.has(modRoleId)
}

const expireTimeMS = 20000

botMsg.awaitReactions({ filter, time: expireTimeMS })
.then(collected => {
console.log(collected.size)
if (member.roles.cache.has(administratorRoleId)) {
//console.log('User is already an administrator!')
return
}
if (collected.size >= modsRequired) {
member.roles.add(administratorRoleId)
channel.send(`confirmation here`)
}
});
const filter = (reaction, user) => {
const userMember = guild.members.cache.get(user.id)
console.log(reaction.emoji.name === '🔑' && userMember.roles.cache.has(modRoleId))
return reaction.emoji.name === '🔑' && userMember.roles.cache.has(modRoleId)
}

const expireTimeMS = 20000

botMsg.awaitReactions({ filter, time: expireTimeMS })
.then(collected => {
console.log(collected.size)
if (member.roles.cache.has(administratorRoleId)) {
//console.log('User is already an administrator!')
return
}
if (collected.size >= modsRequired) {
member.roles.add(administratorRoleId)
channel.send(`confirmation here`)
}
});
console output when 2 users react:
true
true
1
true
true
1
it prints true twice in the filter, but the collected.size is only 1. What am I doing wrong? If no users react, it does print zero. please @ me if someone responds, server is on @s only
10 Replies
d.js toolkit
d.js toolkit•5mo 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
Ardi
ArdiOP•5mo ago
🤔
duck
duck•5mo ago
while the event emits per user, MessageReaction is per emoji so since you seem to only be collecting for a single emoji, it's always going to only have one MessageReaction you'd be looking for <MessageReaction>.users.cache.size
Ardi
ArdiOP•5mo ago
I see. I'm not at my computer right now, what would be the generally standard way to get the specific messagereaction I want from the collector? Would I just want to find 🔑 in collected?
duck
duck•5mo ago
well since there's only one item in the collection, you can just use <Collection>.first()
Ardi
ArdiOP•5mo ago
Was going to ask about other reactions but yeah my filter does force only one reaction. What if the collection is empty?
duck
duck•5mo ago
well if there were multiple in the collection, yes it's keyed by unicode character (or id in the case of custom emojis), so you can get 🔑 if the collection is empty first will return undefined
Ardi
ArdiOP•5mo ago
alright I can just add a check for if its empty Alright, so I'm able to collect multiple users. However, the filter isn't applied to <MessageReaction>.users so if people who got filtered out reacted it still shows up in the users I got.
duck
duck•5mo ago
I suppose you could just filter the users after the fact and only use the collector's filter for the emoji
Ardi
ArdiOP•5mo ago
That's what I was thinking. This was the solution, thanks.
Want results from more Discord servers?
Add your server