I want my if command to detect different forms of the phrase. For example, in this case the phrase is Welcome
. I want my if command to detect for different phrases such as welcome
, Welcome
, WElcome
. Basically the phrase but it doesn't matter if the word or phrase is case sensitive. However, =
, ==
, or ===
doesn't work.
Code:
if (args[1] == "welcome") {
Mongodb.findOne({ guildId: message.guild.id, status: "Welcome" }, async (err, data) => {
if (err) throw err;
if (data) {
data.Channel = channel.id;
data.save();
} else {
new Mongodb({
guildId: message.guild.id,
channelId: channel.id,
status: "Welcome"
}).save();
}
message.channel.send(`The welcome channel has been set to ${channel}!`);
});
}
What I would reccommend using is a Regex. You will need to write:
args[1].match(/welcome/gmi);
OR
args[1].match(new RegExp("welcome", "gmi"))
I would recommend using regex101 for any Regex problems. https://regex101.com/
Finally you can also use.toLowerCase to args[1] and match that with the lowercase version. However, the regex will probably be more efficient.
if(args[1].toLowerCase() === "welcome"){// do stuff}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.