【问题标题】:Discord.js bot will not perform .thenDiscord.js 机器人不会执行 .then
【发布时间】:2020-12-24 22:36:49
【问题描述】:

我正在尝试创建反应消息,但每当我尝试在 .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 收集的大小。任何人都可以帮助我完成这项工作吗?

【问题讨论】:

    标签: javascript discord discord.js


    【解决方案1】:

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

    这里有一些资源:https://discordjs.guide/popular-topics/collectors.html#reaction-collectorshttps://discord.js.org/#/docs/main/stable/class/Message?scrollTo=createReactionCollector

    【讨论】:

      【解决方案2】:

      尝试用console.log(collected) 替换console.log(collected.size),看看效果如何。

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2020-09-08
        • 2018-07-28
        • 2020-10-24
        • 2021-12-06
        • 2021-10-10
        • 2018-06-18
        • 2021-08-04
        • 2021-07-01
        相关资源
        最近更新 更多