Andrew Coalter
Andrew Coalter

Reputation: 33

How to send a message when user says word in a sentence

I want the sans to be left alone, with the current code here it doesn't matter where sans, is it will activate. ex: usansu, I do not want that to work, I want it so sans only works while separate like ex: u sans u. I have commands that use "sans" in it and this gets in the way of that.

Upvotes: 0

Views: 501

Answers (1)

T. Dirks
T. Dirks

Reputation: 3676

A way to do that is to get the message and split it into words. Then you can check if the array contains the word "sans" without any extra characters.

Example code:

bot.on ('message', function (message){
  const words = message.content.split(' ');

  if(words.includes('sans'))
  {
    message.channel.send("<:download:519723756403425294>");
  }
});

Upvotes: 1

Related Questions