1
    bot.on('message', message => {

        if (message.content === 'This is a test') {
           message.channel.send("Hello!");

        }
});

So I want the bot to recognize the sentence even if it is spelled something like this: "THIs iS A tEsT"

  • 3
    Just compare either lower or uppercases of both. To detect it anywhere in the sentence use `indexOf`. `message.content.toLowerCase().indexOf('this is a test') !== -1` – Lain Jun 19 '20 at 21:18
  • That really helped me! Thanks – YourAnonymousGuide125 Jun 19 '20 at 21:24
  • Does this answer your question? [How to do case insensitive string comparison?](https://stackoverflow.com/questions/2140627/how-to-do-case-insensitive-string-comparison) – user120242 Jun 19 '20 at 22:20

1 Answers1

0

You can do:

if (message.content.toLowerCase().includes('this is a test')) {
           message.channel.send("Hello!");
        }
Giuliopime
  • 707
  • 4
  • 21