【问题标题】:How to ignore the first 2 bot reactions?如何忽略前 2 个机器人反应?
【发布时间】:2018-10-24 23:54:58
【问题描述】:

我正在尝试测试某人何时对机器人在嵌入中发布的 2 个表情符号之一做出反应,但当机器人对 ???? 做出反应时在嵌入时它会触发 if (reaction.emoji.name === '????') 语句,我不确定如何忽略机器人的前两个反应,人们可以对其做出反应

let msg2 = await orderChannel.send({embed: embed});
msg2.react('✅');
msg2.react('????');
 const reactions = await msg2.awaitReactions(reaction => reaction.emoji.name == '✅' || reaction.emoji.name == '????', {time: 86400000, max: 1});
 let reaction = await reactions.first();

if (reaction.emoji.name === '✅') {
    await msg2.delete();
    await msg.author.send(`Your order was completed. Please come to the pharmacy with $ ${howmany}000`);
    return;
};

if (reaction.emoji.name === '????') {
    await msg2.delete();
    await msg.author.send(`Your order has been delayed, please message Pixel for info.`);
    return;
};

};

【问题讨论】:

    标签: discord.js


    【解决方案1】:

    在我看来,这将是最好的。过滤器检查检查表情符号和作者或 D 表情符号和作者。因此,如果机器人或其他任何人对此作出反应,它就会忽略它。

    let filter = (reaction, user) => reaction.emoji.name == '✅' && user.id == msg.author.id || reaction.emoji.name == '?' && user.id == msg.author.id;
    const reactions = await msg2.awaitReactions(filter, {time: 86400000, max: 1});
    

    这在 OR (||) 之前执行 AND (&&) 时效果很好。

    我还稍微调整了格式以使其更易于阅读。 (分离成一个过滤变量)

    【讨论】:

      【解决方案2】:

      我能想到的最快解决方法是使用MessageReaction.count 属性,它计算消息中相关反应的数量。在你的情况下,你可能会说 if (reaction.emoji.name === '✅' && reaction.count > 1) {. . .}

      【讨论】:

        猜你喜欢
        • 2019-06-01
        • 2022-01-23
        • 1970-01-01
        • 2021-06-13
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2021-06-28
        • 2022-10-30
        相关资源
        最近更新 更多