首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >命令重叠?

命令重叠?
EN

Stack Overflow用户
提问于 2019-05-05 13:40:04
回答 1查看 496关注 0票数 0

我正在尝试用JavaScript和node.js做一个有趣的不和谐聊天机器人,我想在不影响我已经设置的另一个命令的情况下输入一个特定的命令。

她在我给她的所有服务器上都工作得很好,我已经设置好了,这样当服务器上有人说"rei are“的时候,她就会用来自areResponses的常量来响应。

代码语言:javascript
复制
//const!!!
const areResponses = ["HELL yeah!", "Yep!", "I'm pretty sure that's true!", "I\'m not gonna put all the responses here because then it'd be too long..."];

//theres some other bot stuff (console log, now playing) under here but it isn't relevant until...

//the basics...
      if (message.content.toLowerCase().includes("rei are")) {
          var response = areResponses [Math.floor(Math.random()*areResponses.length)];

          message.channel.send(response).then().catch(console.error);
      }

我想要的是,最好是,这个命令在不触发我编码的"rei are“命令的情况下起作用。

代码语言:javascript
复制
if(message.content.toLowerCase().includes("rei are you happy")) {
           message.channel.send("Yes, absolutely.");
       }

到目前为止,每当我尝试输入上面的命令时,它只会触发"rei are“命令和"rei are you happy”命令,并显示两条消息...

EN

回答 1

Stack Overflow用户

发布于 2019-05-05 15:11:24

else/if链实际上很好地解决了这个问题!

代码语言:javascript
复制
      if(message.content.toLowerCase().includes("rei do you like girls")) {
            message.channel.send("Yes, absolutely. Girls are just... yeah...");
         }
      else if (message.content.toLowerCase().includes("rei are")) {
          var response = areResponses [Math.floor(Math.random()*areResponses.length)];

          message.channel.send(response).then().catch(console.error);
        }

您所需要做的就是将与更大的命令重叠的命令放在else if链的最底部,然后就可以了!

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/55989150

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档