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

180
Visualizações
Discord.js v13 why is this code not working?

I wanted to make my bot say whatever I tell it to by using a command. I have the code copied from other parts of my bot and it is working there yet here it just doesn't and I can't understand why. There are no error messages. Here's my code:

const { Permissions } = require('discord.js');

module.exports = {
    name: 'say',
    description: "Sprawia że coś mówię.",
    execute(message, args)
    {
        let text = args.join(" ").slice(22);
        if(text)
        {
            message.channel.send(text)
        }
        else 
        {
            message.reply('test')//show correct usage
        }
    }
}

(const {Permissions} will be used later so don't worry about it being there) Also you can see what it looks like on discord: here.

about 4 years ago · Juan Pablo Isaza
1 Respostas
Responde à pergunta

0

The code is working exactly how you have programmed it. Take a look at this line:

let text = args.join(" ").slice(22);

Assuming your args in the test case "rp say xd" are just supposed to be "xd", the above code is entirely wrong. The code combines the args, separating them with spaces, and then gets a substring of that starting from the 22nd character. In other words, for text to be anything other than an empty string, your args would have to be over 22 characters long ("rp say xdddddddddddddddddddd!" would make text equal just the ending "!").

Because text is always an empty string for args under 22 characters long, you are basically just doing if (""), which is the same as doing if (false). This means your else statement will always run, unless your args are over 22 characters long combined.

To fix this, do something like this instead:

let text = args.join(" ");

Or, if you meant to make your bot only use the first 22 characters of args provided to it:

let text = args.join(" ").slice(0, 22); //.slice(startIndex, endIndexExclusive)
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