[英]Javascript ignore case
quick question here. 在这里快速提问。 Im writing a discord bot in discord.js, which uses javascript.
我在discord.js中编写了一个使用JavaScript的discord机器人。 Here is a snippet of my current code:
这是我当前代码的一个片段:
if (message.content.includes("hello")){ message.react("👍")}
This, however, only returns the react if it is in that exact case, not if it is Hello, HELLO or helLO. 但是,只有在这种情况下才返回反应,如果是Hello,HELLO或helLO,则不返回反应。 How could i change the code so it accepts all variations?
我如何更改代码,使其接受所有变化?
Many thanks for any answers 非常感谢您的任何回答
You may use following snippet to find case insensitive matches. 您可以使用以下代码段查找不区分大小写的匹配项。
let message = "Okay google Chrome say Hello"; let regex = new RegExp("hello","gi"); if(message.match(regex)){ //react console.log("Reacting"); }else{ console.log("Not reacting"); }
You to can convert one side or both into lower or uppercase and then compare. 您可以将一侧或两侧都转换为小写或大写,然后进行比较。
var message = "Hello World";
if(message.toLowerCase().includes("hello".toLowerCase()){
message.react("👍")
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.