The reason I ask this is because I have a discord bot that responds to commands, but it only works if it is lowercase, so the command "hey bot" returns hello @user but "hey BOT" doesn't work.
Asked
Active
Viewed 301 times
3
-
1Just use javascript's native toLowerCase method... `"SoMe StRiNg".toLowerCase();` returns `"some string"`... The `/` should be returned as `/`, so there shouldn't be a problem with that. – Shmack Dec 19 '20 at 05:06
-
Does this answer your question? [How to do case insensitive string comparison?](https://stackoverflow.com/questions/2140627/how-to-do-case-insensitive-string-comparison) – Joshua Varghese Dec 19 '20 at 12:58
1 Answers
2
In javascript, you can do string.toLowerCase();
function, to convert a string to lower case. For example, in the code below, if you say "hey bot" it works, but if you say "HEY BOT", it will not respond:
client.on('message', message => {
if(message.content == "hey bot" {
message.reply("Hey user!");
}
});
If we want it to ignore case, do the following:
client.on('message', message => {
if(message.content.toLowerCase() == "hey bot" {
message.reply("Hey user!");
}
});
Now that will work whether we type "hey bot", "hey BoT" or "HEY BOT".

Yankue
- 388
- 6
- 14