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

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

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