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

220
Visualizações
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 Respostas
Responde à pergunta

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 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