Reputation: 99
Right now I have it so below if just the bots username is said, I'd like for if a user said the bots username anywhere below in a message the bot would see it.
Likewise this would be a learning experiment for me to understand how to do this with other words as well, like how to find a message with AAPL inside of it, my next step would be to find it in lower case or with one letter capped, etc.
if (message.content.startsWith("<@554504420206051328>")) {
message.channel.send('My advice to you, is buy AAPL.');
} else
Upvotes: 1
Views: 361
Reputation: 14187
The .includes()
function is the one you are looking for :
if (message.content.includes("<@554504420206051328>")) {
message.channel.send('My advice to you, is buy AAPL.');
}
You can check this function documentation if you want more information.
Now for the second part of your question (searching for AAPL
in a message), it is practically the same as the first :
if (message.content.toLowerCase().includes("aapl")) {
message.channel.send('I found AAPL');
}
The .toLowerCase()
function puts the content of the message caught in lower case. So when you are looking for aapl
, you are actually looking for AAPL
, aapl
, Aapl
, etc.
Upvotes: 3