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

167
Views
Making a bot with discord.js, how to make my bot detect a certain phrase?

I'm making a bot that will ping me if a certain phrase gets said in my discord. Currently I am using

if(message.content.toLowerCase() === 'word')

How can I make it so it will detect "word" in any sentence? New to coding so I just followed a guide and after a few hours I couldn't figure it out. I only got it to ping me if only "word" was said and nothing else.

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

0

A simplistic solution is:

function contains(content, word) {
    return (content.toLowerCase().indexOf('word') >= 0);
}

console.log(contains("This is the word!")); //true
console.log(contains("This is WordPress")); //true
console.log(contains("Something")); //false

As you can see, the second example is incorrect, because WordPress semantically differs from word. So, if it's not enough to find the word, but we want to isolate it as well, then we can do something like this:

function contains(content, word) {
    let pattern = new RegExp("[^a-z]" + word + "[^a-z]");
    return (pattern.test(content.toLowerCase()));
}

console.log(contains("This is the word!", "word")); //true
console.log(contains("This is WordPress", "word")); //true
console.log(contains("Something", "word")); //false

In this second example, I prepend and append [^a-z], which means "not a letter"

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!