Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

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?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>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

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading