简体   繁体   中英

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.

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>");
  }
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM