【问题标题】:Having trouble with await reactions等待反应有问题
【发布时间】:2019-10-29 22:08:18
【问题描述】:

我希望机器人在用户使用特定表情符号对消息做出反应后删除它的消息。当我用下面的代码尝试这个时,没有任何反应。没有任何错误。我也不想要时间限制,只要有反应就去做。当前代码:

const filter = (reaction, user) => {
    return ['????'].includes(reaction.emoji.name) && user.id === message.author.id;
};

message.awaitReactions(filter, { max: 1})
    .then(collected => {
        const reaction = collected.first();

        if (reaction.emoji.name === '????') {
      sentMessage.delete(1000)
        } else {
            message.reply('you reacted with a thumbs down.');
        }
    })
    .catch(collected => {
        console.log(`After a minute, only ${collected.size} out of 4 reacted.`);
        message.reply('you reacted with neither a thumbs up, nor a thumbs down.');

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    您的过滤器是什么样的?我们看不到它的第一行。您的问题是您尝试检查表情两次。一次在过滤器中,然后再次在函数中。仅在此处使用过滤器,或者如果您想要多个表情,请使用该功能(我不推荐它)。

    我的解决方案如下所示:

    var message = msg.channel.send("test message");
        const filter = (reaction, user) => reaction.emoji.name === ':ok_hand:' //whatever emote you want to use, beware that .await.Reactions can only check a singel emote
        message.then(m=>{m.awaitReactions(filter, { max: 1})
            .then(collected => {
                console.log("do what ever");
                m.delete();//such as this
            })
            .catch(console.error);
         });
    

    这对我有用。请记住,#awaitReactions 不是很通用。如果您想要与消息交互的多种方式,您可能需要查看#createReactionCollector,它的工作方式相同,但会在每次表情更改时触发。

    希望我能帮上忙。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-12-30
      • 2020-10-16
      • 2019-10-21
      • 1970-01-01
      • 2018-08-19
      • 2011-11-11
      • 2017-12-27
      • 1970-01-01
      相关资源
      最近更新 更多