【问题标题】:how to make if (message.content.startsWith('')) detect for 2 things如何让 if (message.content.startsWith('')) 检测两件事
【发布时间】:2019-08-11 15:01:31
【问题描述】:

所以我有代码

if (message.content.startsWith('')) 

在我的脚本中,我希望它可以通过,如果它是大写或小写。我试过了

if(message.content.startsWith('>command', '>COMMAND')) 

但这没有用。谁能告诉我正确的代码?

【问题讨论】:

    标签: javascript bots discord


    【解决方案1】:

    匹配前可以先将值改为小写

    message.content.toLowerCase().startsWith(">command")
    

    您可以使用搜索

    message.content.seach(/^>command/i)
    

    【讨论】:

      【解决方案2】:

      使用RegExp#test 和正则表达式^>command(其中^start anchor)和flag i 忽略大小写。

      if(/^>command/i.test(message.content)))
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 2020-09-30
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多