Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

372
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda