【问题标题】:Filter String/Array for multiple conditions [duplicate]过滤多个条件的字符串/数组[重复]
【发布时间】:2022-02-05 11:09:59
【问题描述】:

这是我下面的代码,基本上我希望机器人检查两件事。用户消息需要包含“how”+“doing”或“bread”。当我只使用“做”而不是当我添加“面包”条件时,它工作得很好。 我需要一个干净简单的解决方案,希望有人能帮助我,对我来说,这是归档我需要的最合乎逻辑的方式:D

if(msg.content.includes("how") && msg.content.includes("doing" || "bread") ){

    if(msg.author != token){ 
        msg.lineReply("I am good sir")
        }

}

【问题讨论】:

  • 你检查过"doing" || "bread" 做了什么吗?
  • 我找不到我的代码的不同之处:你的意思是没有括号?那是行不通的,因为我使用的是 .includes 函数

标签: javascript npm discord discord.js


【解决方案1】:

if(msg.content.includes("how") && (msg.content.includes("doing") || msg.content.includes("bread")) ){

    if(msg.author != token){ 
        msg.lineReply("I am good sir")
        }

}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2019-01-16
    • 2021-12-09
    • 2021-07-23
    • 2014-11-20
    • 2016-04-03
    • 1970-01-01
    • 2021-01-27
    • 2018-08-09
    相关资源
    最近更新 更多