简体   繁体   中英

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?

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

尝试更换console.log(collected.size)console.log(collected) ,看看它是如何工作的。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM