Await reaction & loop

Hi. I am trying to use .awaitReactions() to run the addUserToGiveaway on every reaction added to message. But, it only works after the "max" value is reached or timeout happens. I wanna make it such that the code inside it runs on every reaction added. How do I do?
giveawayMessage.awaitReactions({ max: 1000, time: parseDuration(duration) })
.then(collected => {
console.log(Date.now())
const reaction = collected.first();
if (reaction) {
const usersArray = Array.from(reaction.users.cache.values()).filter(user => !user.bot);// Filter out bots and creates array
for (let i = 0; i < winnersCount && i <= usersArray.length; i++) {
addUserToGiveaway(giveawayMessage.id, usersArray[i].id);
}
}
})
.catch(console.error);
giveawayMessage.awaitReactions({ max: 1000, time: parseDuration(duration) })
.then(collected => {
console.log(Date.now())
const reaction = collected.first();
if (reaction) {
const usersArray = Array.from(reaction.users.cache.values()).filter(user => !user.bot);// Filter out bots and creates array
for (let i = 0; i < winnersCount && i <= usersArray.length; i++) {
addUserToGiveaway(giveawayMessage.id, usersArray[i].id);
}
}
})
.catch(console.error);
This is just a part of code. All the things like giveawayMessage and addUserToGiveaway have been declared and no other errors.
2 Replies
d.js toolkit
d.js toolkit15mo 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
NanotechPikachu
NanotechPikachuOP15mo ago
Hmmm lemme try Thanks very much. It worked. heartlove I am closing this then. Thnx again.
Want results from more Discord servers?
Add your server