【问题标题】:Bot sends reaction message without a reaction机器人发送反应消息而没有反应
【发布时间】:2020-08-02 03:47:02
【问题描述】:

所以我的机器人现在在第一条消息之后立即发送“A”反应消息,但用户没有反应。它不应该那样做。为什么?我没有错误。

client.on("guildMemberAdd", member => {
    try {
        member.send(`Hello ${member}, welcome to the PotatoHost Server! 
I want to help you and so my question is: Do you want to buy a server or do you need more informations first? \n
A: I want to buy a server
B: I need more informations first \n
Please react to this message with A or B.`)

        .then(function (message) {
            message.react("????")
            message.react("????")

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

            message.awaitReactions(filter, { max: 1, time: 3600000, errors: ['time'] })
                .then(collected => {
                    const reaction = collected.first();

                    if (reaction.emoji.name === '????') {
                        message.channel.send('Ok, so you want to buy a server. Let me recommend you to visit <#699374469977735208>.');
                    }
                    else {
                        message.channel.send('Ok, so you need more informations first. Let me recommend you to visit <#699374469977735208>.');
                    }    
                })
                .catch(collected => {
                    message.channel.send('You reacted with neither A or B.');
                })
        });
    }catch (err) {
         console.log(err)
    }
})

【问题讨论】:

    标签: javascript reactjs bots discord.js message


    【解决方案1】:

    看来您正在覆盖原来的message 对象。在您的过滤器中,您要确保它是会员的 id,这样其他人就不能认领它,

    && user.id === message.author.id
    

    但是,在这种情况下,message 指的是您的机器人正在发送的消息 —.then(function (message) {。因此,您的代码会读取过滤器,因为 ID 必须与您的机器人匹配,并且由于您的机器人与 A 做出反应,它会吐出 A 反应消息。

    要解决此问题,请将前面所述的过滤器更改为

    && user.id === member.id
    

    编辑

    第二个问题:B。你的过滤器只找到?或B,你需要把B改成return ['?', 'B']中的emoji版本。

    【讨论】:

    • 非常感谢你,你是对的,所以现在当我对 A 做出反应时,它会发送消息 A,但是当我对 B 做出反应时,它不会发送任何消息(没有错误)。你知道为什么吗?
    • @NicoHd105 编辑了我的答案以包含它;希望它有所帮助:)
    • 你又是对的。 100 次感谢,祝你一切顺利。
    • 没问题!为了帮助其他人,请点击复选标记将此问题标记为正确。祝你有美好的一天!
    猜你喜欢
    • 2021-07-04
    • 1970-01-01
    • 2020-09-28
    • 2020-04-29
    • 1970-01-01
    • 2021-04-11
    • 2023-01-24
    • 2020-07-11
    • 2020-11-17
    相关资源
    最近更新 更多