【问题标题】:Discord.js awaitmessage error, how to fix?Discord.js 等待消息错误,如何解决?
【发布时间】:2020-12-11 12:06:29
【问题描述】:

我正在制作这个新机器人并使用了 awaitmessage 功能。当用户使用 cmd '!gangsug' 时,机器人应该会问一个问题,例如 - “请选择一个选项 - RP 或战斗”,当用户使用它应该给出答复的选项。 (这是一个嵌入)。对于用户给出的 2 个答案,我给出了两种不同的答复。(一个用于回答“RP”,另一个用于回答“Fight”)。在这种情况下,机器人对两个答案给出相同的答案。如果用户键入“RP”或“Fight”,则给出相同的回复 由机器人。我希望你理解这个问题。代码将在下面给出(ofc只是问题出现的部分)

if (message.content === `${prefix}gangsug`) {

                  message.reply('Hey there! Please choose a option.\n'
                          + 'Confirm with `RP` or with `Fight`.');

                  // First argument is a filter function - which is made of conditions
                  // m is a 'Message' object
                  message.channel.awaitMessages(m => m.author.id == message.author.id,
                          {max: 1, time: 30000}).then(collected => {
                                  // only accept messages by the user who sent the command
                                  // accept only 1 message, and return the promise after 30000ms = 30s

                                  // first (and, in this case, only) message of the collection
                                 if (collected.first().content.toLowerCase() == 'RP') {
                                          message.reply(suggestgang1);
                            
                                  }

                                  else
                                          message.reply(suggestgang2);
                                          message.reply(suggestgang3);    
                                        
                          }).catch(() => {
                                  message.reply('No answer after 30 seconds, req canceled.');
                          });
                  
       }       }  
  
);

**是的,这是代码。如果您能通过说明问题和替换此代码的固定代码来给出答案,那就太好了。谢谢:) **

【问题讨论】:

    标签: javascript node.js discord.js


    【解决方案1】:

    我认为问题出在这一行:

    if (collected.first().content.toLowerCase() == 'RP')
    

    由于您对消息内容使用了.toLowerCase() 方法,因此在物理上不可能匹配任何大写字母,例如“RP”。

    if (collected.first().content.toLowerCase() == 'rp')
    

    【讨论】:

    • 哦,该死的!我从来没有那样过,谢谢你..让我试试
    猜你喜欢
    • 2020-07-02
    • 1970-01-01
    • 2021-03-07
    • 2019-01-02
    • 1970-01-01
    • 2020-12-03
    • 2020-10-18
    • 2022-01-21
    • 2021-11-03
    相关资源
    最近更新 更多