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

217
Vistas
How to check which message is sent and return reply accordingly?

I'm building a discord bot and I want the bot to reply based on what input I give. My JSON file looks like this.

const greetings = [
    {
        id: 1,
        received: [
            "Hi",
            "Hi there",
            "Hello",
            "Hey",
            "Hey there"
        ],
        reply: "Hi there"
    },
    {
        id: 2,
        recived: [
            "Wassup",
            "Sup"
        ],
        reply: "Nothing much. Wassup",
    },
    {
        id: 3,
        received: [
            "How are you doing",
            "How are you doing?",
            "How have you been doing",
            "How have you been doing?",
        ],
        reply: "I'm good. And I hope you're doing well too",
    },
];

When I send a message like Hi or Hello there, I want it to respond with Hi there. And when I send a message like How are you doing, it should reply with I'm good. And I hope you're doing well too.

How do I check which message is sent and return the appropriate reply?

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

0

You can use Array.find to find an array item with its value and Array.some to check if it exists.

The code would be:

if (greetings.some(x => x.received.includes(message.content))) {
  message.channel.send(greetings.find(x => x.received.includes(message.content)).reply);
})
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