【问题标题】:Awaiting reactions in discord.js not working等待 discord.js 中的反应不起作用
【发布时间】:2021-08-12 07:51:19
【问题描述】:

我目前有一个 messageReactionAdd,之后它将 DM 嵌入,这可以工作,但现在我想听那个 DM 的反应,但它只是对话中的一条消息,所以它不需要听它。我可以在我的 messageReactionAdd 中发送一个 DM,它也会对正确的项目做出反应,但是当我对竖起大拇指做出反应时,它不会像我一样记录测试,这是我的代码:

     member.send(currentEmbed).then((message) => {
      //Iterate through the dividers
      for(var j = 0; j < dividers.length; j++) {
        //Create variable to dump current number in emoiji form
        var number = "";
        //Convert digit to emoji form
        switch(dividers[j]) {
            case 1:
                number = "????";
                break;
            case 2:
                number = "2️⃣";
                break;
            case 3:
                number = "3️⃣";
                break;
            case 4:
                number = "4️⃣";
                break;
            default:
                number = "";
                break;               
        }
        //React a message with the current digit in emoji form
        message.react(number);           
      }
      //Await the thumbsup reaction **DEBUGGING
      message.awaitReactions(reaction => reaction.emoji.name === "????", {time: 150000}).then(msg => {
            console.log("TEST");
        });
    });

不要介意复杂的 for 循环,它只是为了反应所有可能的组合,而且效果很好。

【问题讨论】:

    标签: javascript discord.js


    【解决方案1】:

    事件 messageReactionAdd 对缓存消息起作用,正如他们在文档 https://discord.js.org/#/docs/main/stable/class/Client?scrollTo=e-messageReactionAdd 中所说的那样

    每当响应添加到缓存消息时发出。

    所以你可以做的是在准备好的事件中启动机器人时缓存你的消息,如下所示:

    client.on('ready', ()=>{
       client.channels.cache.get(CHANNEL_ID).messages.fetch(MESSAGE_ID);
    });
    

    比 messageReactionAdd 事件更有效。

    【讨论】:

      猜你喜欢
      • 2021-12-30
      • 2021-01-27
      • 2021-03-07
      • 2019-05-04
      • 1970-01-01
      • 2018-09-21
      • 1970-01-01
      • 2019-10-21
      • 1970-01-01
      相关资源
      最近更新 更多