0

When code is:

client.on('message', msg => {
  const args = msg.content;
  const command = args.toLowerCase()

  if (command === 'frick'){
    msg.reply('Sorry Sir this is a Christian server so no swearing! >:(');
  }
});

message is sent normally

and when I added 'shit' to it

client.on('message', msg => {
  const args = msg.content;
  const command = args.toLowerCase()

  if (command === 'frick' || 'shit'){
    msg.reply('Sorry Sir this is a Christian server so no swearing! >:(');
  }
});

this was a result it just looped

and I know I can add a line which ignores bots but I want it to be active for bots as well

SzymCrusader
  • 3
  • 1
  • 4

2 Answers2

1
  1. Your if statement always evaluates to true, because you are essentially checking if ('shit'), which is truthy because its length is greater than 0.
  2. You aren't ignoring bot messages. So you're creating an infinite loop where bot sends message -> bot receives own message -> bot sends message -> bot receives own message -> ....

To fix 1, make sure you write your if statements properly:

if (command === 'frick' || command === 'shit') {

And to fix 2, you can add a simple if to the start of your message handler to check if the author is a bot:

if (msg.author.bot) {
  return;
}
0

To make it even shorter you could do:

if (command === ('frick' || 'shit')) {
VeneerLarry
  • 17
  • 2
  • 11