【问题标题】:How to fix timeout error when using awaitReactions() function?使用 awaitReactions() 函数时如何修复超时错误?
【发布时间】:2021-09-24 05:05:41
【问题描述】:

我已经在我的 Bot 中编写了这段代码,但它不能正常工作。 awaitReactions()函数总是超时:

message.channel.send({ embed: hEmbed }).then(embedreacted => {
        embedreacted.react('????').then(() => embedreacted.react('????'));

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

        embedreacted.awaitReactions(filter, { max: 1, time: 20000, errors: ['time'] })
            .then(collected => {
                console.log("col" + collected)
                const reaction = collected.first();
                if (reaction.emoji.name == '????') {
                    let hlembed = new Discord.MessageEmbed()
                        Embed
                    embedreacted.edit({ embed: hlembed });
                } else if (reaction.emoji.name === '????') {
                    let hfEmbed = new Discord.MessageEmbed()
                     Embed
                    embedreacted.edit({ embed: hfEmbed });
                }
                for (const [key, value] of Object.entries(reaction)) {
                    console.log(key, value);
                }

            })
            .catch(collected => {
                console.log("collected \n" + collected.keys())
            });

【问题讨论】:

  • @Toasty - 你知道为什么这不起作用吗?
  • 你想永远听听对此消息的反应还是只听 20 秒?
  • @Toasty - 仅持续 20 秒,但 awaitReactions 函数没有给出结果
  • 也许this answer 可以解决您的问题
  • @Toasty - 现在他做了他应该做的事情,但当机器人自己对它做出反应时他也这样做了,我只希望机器人只在消息作者时做某事有反应,但是当我尝试添加“&& user.id === message.author.id”时它不再起作用了。

标签: javascript node.js discord.js bots


【解决方案1】:

在您的filter 函数中:

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

message.author.id 是机器人的用户 ID,因为正在“等待”反应的消息是由机器人创建的。因此条件user.id === message.author.id 只会在机器人的用户对其做出反应时触发。

我不确定这是否是您想要的,但如果您希望它仅在用户对其做出反应(而不是机器人本身)时触发,只需执行 user.id !== <Client>.user.id 甚至 user.id !== message.author.id 作为快捷方式。

如果您只希望收到之前创建此消息的用户的反应,您需要将 <Message> 对象设置为变量,然后使用 user.id === variable.author.id

【讨论】:

    猜你喜欢
    • 2021-11-17
    • 2019-11-30
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-05-31
    • 2019-06-18
    • 1970-01-01
    • 2021-12-01
    相关资源
    最近更新 更多