Issue
I am writing a program that looks for specific keywords and then only performs an action when a keyword is present in a message. I am having difficulty trying to make it so that it will pickup on keywords regardless of their capitalization. Below is an example of what I currently have.
for (var i = 0; i < keyword.length; i++) {
if (msg.content.includes (keyword[i])) {
msg.channel.send("Orange")
}
var keyword = ["Apple","Banana"]
The only way I've figured out how to do this is to add each variation to the keyword list. How would I make it so that it could detect for example "apple" or "BaNaNa" without adding those variations to the keyword list?
Solution
If your message is a string, just make the whole thing lower case and match it to lowercase keywords.
let message = msg.content.toLowerCase();
if (message.includes(keyword[i].toLowerCase()) {
....
}
Answered By - Ed Lucas Answer Checked By - Mildred Charles (PHPFixing Admin)
0 Comments:
Post a Comment
Note: Only a member of this blog may post a comment.