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

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

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 Relatório

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