-3

I'm trying to read any message sent on a discord server and send a reply if a certain string is within the message ignoring all spaces and capitals. I'm very new to javascript and this is the first code I'm making just for fun.

This is the current main part of the code.

if(msg.content.toLowerCase().includes('string'))
  {
     msg.channel.send(emoji("480351478930866179"));
  }
  • 1
    Since you've clearly demonstrated you already have the functionality to remove case-sensitivity concerns, this is a possible duplicate of [Remove whitespaces inside a string in javascript](https://stackoverflow.com/questions/10800355/remove-whitespaces-inside-a-string-in-javascript) – esqew Jun 05 '19 at 16:02

3 Answers3

1

You can remove whitespace with replace() and shift the string to lowercase using toLowerCase() to achieve the desired result.

const original = 'Hello there.';

const str = original.replace(/\s/g, '').toLowerCase();

if (str.includes('hello')) console.log('Hi.');
slothiful
  • 5,548
  • 3
  • 12
  • 36
emcee22
  • 1,851
  • 6
  • 23
  • 32
0

You could use the string.replace method or you could use split then join. To ignore case just use toLowerCase();

0

Thank's, that solved my problem.

const original = 'Hello there.';

const str = original.replace(/\s/g, '').toLowerCase();

if (str.includes('hello')) console.log('Hi.');