Spazzik
Spazzik

Reputation: 13

Have my discord bot respond when two different words are said in one message?

This is a really simple question, but I'm making an incredibly simple bot (small, private friend server) and I can't figure out how to do this, nor have I been able to look up anything that matches what I'm looking for.

How do I make it so that my bot will only respond if two different words are sent in one message?

Here's an example:

 if (message.content.toLowerCase().includes('egg')) {
  message.channel.send(egg(message));
 } else

With the function of "egg(message)" declared elsewhere in the code, of course. My bot will respond to anyone who sends a message with the word "egg" anywhere in it with a randomly generated response, which works fine.

What I want to know is if it's possible to, say, have the bot respond if anyone says the words "egg" and "bacon" in one message. Meaning, I want it to respond if both of those two words are said anywhere in a message, but to not respond if only "egg" or "bacon" is said. I hope that makes sense.

Upvotes: 1

Views: 1246

Answers (1)

Francois S.
Francois S.

Reputation: 224

You can use &&, which stands for and in conditions, like so:

let msg_content = message.content.toLowerCase()
if (msg_content.includes('egg') && msg_content.includes('bacon')) {
  message.channel.send(egg(message));
 }

Upvotes: 1

Related Questions