【问题标题】:How would I make my bot detect a reaction then send a message if the reaction is a specific reaction?如果反应是特定反应,我如何让我的机器人检测反应然后发送消息?
【发布时间】:2020-07-11 21:02:04
【问题描述】:

我正在制作一个有反应的帮助命令,机器人会添加一个反应,然后使用会做出反应,机器人会发布相应的帮助消息。我很困惑为什么我的代码不能正常工作,因为它没有抛出任何错误。

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

message.awaitReactions(filter, { max: 1, time: 5000, errors: ['time'] })
    .then(collected => {
        const reaction = collected.first();
        if (reaction.emoji.name === ':zany_face:') {
            message.reply('test.');
        }
    })
    .catch(collected => {
        message.reply('You didn\'t react in time');
    });

感谢您的帮助:)

Ps:我在嵌入的后面使用它,所以我希望嵌入对它有反应,不过我已经做了一点,只是不确定如何在嵌入和 awaitreaction 之间有效地链接代码

【问题讨论】:

  • 我有几个问题。谁发送了消息,机器人还是用户?另外,你能在你的过滤功能中console.log(reaction.emoji.name, user.id, message.author.id)吗?
  • 用户发送命令 =help,然后机器人发送帮助嵌入,用户使用必要的表情符号做出反应,机器人删除原始帮助嵌入并发送相关的帮助嵌入与表情符号 -反应已添加到机器人的拳头嵌入中 - 可能会更容易向您展示,请随时添加我的 dc:Proto#4992

标签: node.js bots discord discord.js


【解决方案1】:

这应该可以解决问题:

const filter = (reaction, user) => !user.bot && user.id ==usr.id; //makes sure only the message author can react

let msg = message.channel.send("React to me!")

//creates a collector on the message for 5 seconds
let collector = msg.createReactionCollector(filter, { time: 5000 });
//opens the reaction collector
collector.on('collect', async (reaction, collector) => {
    //checks which reaction was given
    const chosen = reaction.emoji.name;

    if(chosen == "EMOJIHERE"){
        //removes the user's reaction
        msg.reactions.get("EMOJIHERE").remove(message.author.id).catch(allerrors)
        //sends a message back
        message.channel.send("This is an answer.")
    }
})

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-02-09
    • 2020-08-02
    • 2020-09-08
    • 2021-11-28
    • 1970-01-01
    • 2020-04-29
    • 2019-10-16
    • 1970-01-01
    相关资源
    最近更新 更多