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

221
Views
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 answers
Answer question

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