Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

218
Views
¿Cómo verificar qué mensaje se envía y devolver la respuesta en consecuencia?

Estoy creando un bot de discordia y quiero que el bot responda en función de la entrada que doy. Mi archivo JSON se ve así.

 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", }, ];

Cuando envío un mensaje como Hola o Hola, quiero que responda con Hola. Y cuando envío un mensaje como ¿Cómo estás?, debería responder Estoy bien. Y espero que tú también lo estés haciendo bien.

¿Cómo verifico qué mensaje se envía y devuelvo la respuesta adecuada?

about 4 years ago · Juan Pablo Isaza
1 answers
Answer question

0

Puede usar Array.find para encontrar un elemento de matriz con su valor y Array.some para verificar si existe.

El código sería:

 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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!