繁体   English   中英

Discord.js bot 不会执行 .then

[英]Discord.js bot will not perform .then

我正在尝试创建一条反应消息,但是每当我尝试在 .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));
}

我的最终目标是让它为所有对它做出反应的用户添加一个角色,但在我删除消息之前,它甚至不会 console.log 收集的大小。 任何人都可以帮助我完成这项工作?

awaitMessages() 只会在消息被删除或时间用完后解析。 您可以做的是创建一个 reactCollector 并等待收集事件。

以下是一些资源: 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