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

159
Visualizações
I'm getting error while making an alias system in discord.js

I was making an alias system for my discord bot, and I wanted to say: "if the user entered the wrong command name or alias then return: invalid command/alias", but I'm getting an error:

C:\Users\Pooyan\Desktop\PDM Bot Main\events\guild\message.js:16
                    if(!cmd || client.commands.find(a => !a.aliases && !a.aliases.includes(cmd))) return message.channel.send('Invalid command');
                                                                                  ^

TypeError: Cannot read properties of undefined (reading 'includes')
    at C:\Users\Pooyan\Desktop\PDM Bot Main\events\guild\message.js:16:83

My code:

module.exports = async (message, client, Discord) => {
    const prefix = process.env.PREFIX;

    if(!message.content.startsWith(prefix) || message.author.bot) return;

    const args = message.content.slice(prefix.length).split(/ +/);
    const cmd = args.shift().toLowerCase();

    const command = client.commands.get(cmd) || 
                    client.commands.find(a => a.aliases && a.aliases.includes(cmd));
                    if(!cmd || client.commands.find(a => !a.aliases && !a.aliases.includes(cmd))) return message.channel.send('Invalid command');
}

I'm using discord.js v13 and Node.js v16.14.2

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

0

I found the solution myself, all I had to do was:

 if(!command) return message.channel.send('Invalid Command/alias');

after those two lines, it means that if the command name was not correct, or if the alias was not correct, it returns "Invalid command/alias"

about 4 years ago · Juan Pablo Isaza Relatório

0

Remove the first ! in your find method, it will fix the error

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