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

310
Vistas
How to use multiple word in "startsWith"
if (message.content.startsWith('let', 'Let')){/do something/})

I want bot work when user type "let" or "Let", but it can just work when "let" typed How to fix this? Thanks for helping

about 4 years ago · Juan Pablo Isaza
3 Respuestas
Responde la pregunta

0

You could use regular expressions here:

var terms = ["let", "Let"];
var regex = new RegExp("^(?:" + terms.join("|") + ")\\b");
var inputs = ["Let it be!", "let it be!", "Green Eggs and Ham"];
for (var i=0; i < inputs.length; ++i) {
    if (regex.test(inputs[i])) {
        console.log("MATCH    => " + inputs[i]);
    }
    else {
        console.log("NO MATCH => " + inputs[i]);
    }
}

To be clear, we are using test() with the regex pattern:

^(?:let|Let)\b

You may add more terms to the above alternation as needed.

about 4 years ago · Juan Pablo Isaza Denunciar

0

To keep things flexible you could keep an array of words you want to check, and then use some to check to see if any of those words are at the beginning of the content string.

const words = ['let', 'Let', 'Bob'];

const message1 = { content: 'let' };
const message2 = { content: 'notlet' };
const message3 = { content: 'Let' };
const message4 = { content: 'Bob' };

function startsWith(message) {
  return words.some(word => {
    return message.content.startsWith(word);
  });
}

console.log(startsWith(message1));
console.log(startsWith(message2));
console.log(startsWith(message3));
console.log(startsWith(message4));

about 4 years ago · Juan Pablo Isaza Denunciar

0

I believe you are looking for case insensitive match. In that case following can work assuming your message.content is a string or object.
Here we collect user typed string in userTypedThis variable.

if (message.content.toString().toLowerCase().startsWith(
   userTypedThis.toString().toLowerCase())
){/do something/})
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