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

122
Vistas
discord.js keeps receiving TypeError: Cannot read property 'name' of undefined
for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.data.name, command);
}

I keep on getting an error

TypeError: Cannot read property 'name' of undefined

and it has been working flawlessly until now. I tried to console.log(command.data) but I can't seem to find what's wrong...

about 4 years ago · Juan Pablo Isaza
2 Respuestas
Responde la pregunta

0

Try replacing command.data.name by command.name.

Your code should work if you have this :

for (const file of commandFiles) {
    const command = require(`./commands/${file}`);
    client.commands.set(command.name, command);
}
about 4 years ago · Juan Pablo Isaza Denunciar

0

This error is telling that the command.data.name line doesn't exists in the file. So this error does not show up because of your index.js file but because one of the files that you are trying to read commands folder. You'll need to make sure that you have added in every file that is being read in the index.js (so in your case all the files in your commands file) in the module.exports the following json line:

module.exports = {
     data: {
         name: 'command_name'
     },
     ....
}
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