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?
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); })