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

373
Views
Javascript/Discord.js-How do I make a bot only respond to a message if it contains a specific word and does not have letters around it
client.on("messageCreate", message => {

    let string = message.content;

    string = string.toLowerCase();

    if (string.indexOf("andy") >= 0) {
        message.channel.send("Test")
    }

})

I was wondering how one would make the code not send "test" if string would be a string like candy where it responds as if the string is andy. I would like it to only respond if the string is andy and not if the string has letters around it which change the meaning of the word.

I am sorry for this basic question but I did not know how to word it when searching for it. Thank you for any help you can provide.

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

0

This would be done by simply checking if the message content matched and includes. By putting a space before and after it will only look for that word if it isn't part of another word like candy or randy.

client.on("messageCreate", async message => {
    if (message.content.toLowerCase().includes(' andy ')) {
        message.channel.send("Test")
    }
})
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!