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

164
Vistas
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 Respuestas
Responde la pregunta

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 Denunciar

0

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

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