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

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

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