Marco Chavez
Marco Chavez

Reputation: 215

Discord.js bot will not perform .then

I am trying to create a reaction message, but whenever I try to use a console.log in the .then it only executes it once the message is deleted.

async execute(message) {
    const role = message.guild.roles.cache.find(r => r.name == 'Founder');
    if (!role) return message.channel.send(`**${message.author.username}**, role not found`);

    await message.delete();

    const filter = (reaction) => reaction.emoji.name === '✅';

    const ReactionMessage = await message.channel.send('React to this message to get the Founder role');

    ReactionMessage.react('✅');

    ReactionMessage.awaitReactions(filter, { max: 10, time: 15000 })
        .then(collected => console.log(collected.size))
        .catch(err => console.error(err));
}

My end game is to have it add a role to all of those users who react to it, but it won't even console.log the collected size until I delete the message. Anyone able to help me get this working?

Upvotes: 0

Views: 49

Answers (2)

Oliver Su
Oliver Su

Reputation: 84

The awaitMessages() will only resolve once either the message is deleted or the time has run out. What you can do instead is make a reactionCollector and wait for the collect event.

Here is some resources: https://discordjs.guide/popular-topics/collectors.html#reaction-collectors, https://discord.js.org/#/docs/main/stable/class/Message?scrollTo=createReactionCollector

Upvotes: 2

Shay
Shay

Reputation: 57

Try replacing console.log(collected.size) with console.log(collected) and see how that works out.

Upvotes: 0

Related Questions