Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

444
Vistas
How do I make my Discord Bot reply a same answer for similar messages? JavaScript

I've been working on a Discord bot. I needed a solution for questions like this: Who are you or who are you.

The above sentences may seem similar but are case sensitive, and I want my bot to reply the same answer to a few similar questions like I showed above. This is What I tried:

import Discord from 'discord.js'
import { Client, Intents } from 'discord.js'

const client = new Client({ intents: [Intents.FLAGS.GUILDS, Intents.FLAGS.GUILD_MESSAGES] });

client.on("ready", () => {
  console.log("Log In Successful!!")
})

client.on("message", msg => {
  if (msg.content === 'hello', 'hey') {
    msg.reply("hi");
  }
})

client.login(process.env.TOKEN)

But when I run it and write the command, it repeats the reply several times.

Any ideas to fix this?

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

The line that is causing the multiple replies is this one:

if (msg.content === 'hello', 'hey'){

Your syntax is slightly off and the 'hey' is not part of the statement like you want it to be. The 'hey' evaluates to true which triggers the if statement's code a second time.

To fix it, you may want to have an array of responses, and check if the user's message is in the array (note the .toLowerCase() means you don't have to worry about capital letters):

greetings = ['hello', 'hey', 'hi']
if (greentings.indexOf(msg.content.toLowerCase()) > -1) {
    // the message is in the array - run your code here
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

You can group similar questions in an array and use Array#includes to check if the question is in that array. You can also make it case-insensitive by using toLowerCase. Something like this:

client.on("message", (msg) => {
  const group = [
    'how are you',
    'how you doin',
    'you alright',
  ]
  if (group.includes(msg.content.toLowerCase())) {
    msg.reply('hi');
  }
})
about 4 years ago · Juan Pablo Isaza Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda