• Jobs
  • About Us
  • professionals
    • Home
    • Jobs
    • Courses and challenges
  • business
    • Home
    • Post vacancy
    • Our process
    • Pricing
    • Assessments
    • Payroll
    • Blog
    • Sales
    • Salary Calculator

0

309
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 3 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 3 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 Our process Sales
Legal
Terms and conditions Privacy policy
© 2025 PeakU Inc. All Rights Reserved.

Andres GPT

Recommend me some offers
I have an error