Avoiding respond to a bots

Hi so im workig on discord bot
and using ping and pong as test
It loops because it respond to itself which bots
so if put message.author.bot === false in every commands its so annoying

client.on("message", message => {
  if(message.content === "ping" && message.author.bot === false){
    message.channel.send("pong")
  } else if(message.content === "pong" && message.author.bot === false){
    message.channel.send("ping")
  }
})

can someone help me?

>Solution :

You need to put if(message.author.bot) return; after client.on("message", message => { and as result get:

client.on("message", message => {
  if(message.author.bot) return;
  if(message.content === "ping" && message.author.bot === false){
    message.channel.send("pong")
  } else if(message.content === "pong" && message.author.bot === false){
    message.channel.send("ping")
  }
})

to ignore messages from bots

Leave a Reply