简体   繁体   English

Discord.js bot 不会执行 .then

[英]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.我正在尝试创建一条反应消息,但是每当我尝试在 .then 中使用 console.log 时,它只会在消息被删除后执行它。

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.我的最终目标是让它为所有对它做出反应的用户添加一个角色,但在我删除消息之前,它甚至不会 console.log 收集的大小。 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. awaitMessages() 只会在消息被删除或时间用完后解析。 What you can do instead is make a reactionCollector and wait for the collect event.您可以做的是创建一个 reactCollector 并等待收集事件。

Here is some resources: https://discordjs.guide/popular-topics/collectors.html#reaction-collectors , https://discord.js.org/#/docs/main/stable/class/Message?scrollTo=createReactionCollector以下是一些资源: 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) ,看看它是如何工作的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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