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

194
Vistas
Discord JS Commands Ran At Once

I'm trying to make a discord Vouch System but when i do -Vouch it runs 2 commands one is -Vouch And the other is -Vouches ```

client.on("message", (message) => {

    if (message.content.startsWith("-Vouches")) {
                  const user = message.mentions.users.first();
          if (user === undefined) {
    return; }
about 4 years ago · Juan Pablo Isaza
1 Respuestas
Responde la pregunta

0

If you always uses startsWith it will surely execute two commands if one of the command name is contained into another one.

For example, if we have this code :

client.on("message", (message) => {
    if (message.content.startsWith("!test")) console.log("test command");

    if (message.content.startsWith("!test2")) console.log("test2 command");
});

Both command will be executed if we write !test.

So a solution vastly used is to split the message by spaces, then take the first word, and test it, not if it starts with a string, test the entire string, like this.

client.on("message", (message) => {
    const [commandName, ...arguments] = message.content.split(/\s+/);
    // commandName is the first word
    // arguments is an array of the other words of the message

    if (commandName === "!test") console.log("test command");

    if (commandName === "!test2") console.log("test2 command");
});

Here we split the message by spaces, using the regular expression \s+, then took the first word and tested it directly. You can also then use the array arguments for your commands stuff.

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