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

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

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