Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
Why my discord bot spams messages by adding the following code?

I am coding a basic moderation bot for Discord in discord.js. But by adding the following code for replying "Hello!" everytime someone sends message from the list, the bot spams a lot of "Hello!" messages in the channel.

client.on("message", async message =>{
  if (message.content == "Hi" || message.content == "hi" || message.content == "hello" || message.content == "Hello" || message.content == "hi!" || message.content == "Hi!" || message.content == "Hello!" || message.content == "hello!")
  {
    message.channel.send(`Hello!`)
  }
});

Can someone explain why does this happen and provide a solution to it? I tried to search on the web but was not able to phrase the question properly, so I got no answers.

P.S.: I am still learning JavaScript and I am coding this in replit.com, if that matters!

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

As esqew pointed out in their comment, your bot is stuck in an event loop of replying to its own message. An easy way to deal with this problem would be to ignore messages from either all bots, or just the bot's own messages, as demonstrated below.

client.on("message", async message => {
    // Method A: Ignore all Bots
    if(message.author.bot) return;

    // Method B: Ignore self only
    if(message.author.id == client.user.id) return;

    // Insert rest of event code here, etc...
});

See User.bot (Discord.js Docs)

about 4 years ago · Juan Pablo Isaza Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda