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

186
Visualizações
Why is command.data undefined when all of my commands are exporting data objects in discord.js?

So currently I have a bot that uses discord.js and every time I try to use my deploy-commands.js file, I get an undefined error that says Cannot read properties of undefined (reading 'name') (when reading command.data.name). This has confused me because apparently, from reading other articles similar to this one, it's usually due to someone having a file that does not export a data object in their commands folder; however, all of mine do. What can I do to fix this?

my deploy-commands.js file:

const fs = require('node:fs');
const path = require('node:path');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { clientId, token } = require('./config.json');

const rest = new REST({ version: '9' }).setToken(token);

const commands = [];
const commandsPath = path.join(__dirname, 'commands');
const commandFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith('.js'));

for (const file of commandFiles) {
    const filePath = path.join(commandsPath, file);
    const command = require(filePath);
    commands.push(command.data.toJSON());
}

const buttonCommands = [];
const buttonCommandsPath = path.join(__dirname, 'buttonCommands');
const buttonCommandFiles = fs.readdirSync(buttonCommandsPath).filter(file => file.endsWith('.js'));

for (const file of buttonCommandFiles) {
    const filePath = path.join(buttonCommandsPath, file);
    const command = require(filePath);
    buttonCommands.push(command);
}

module.exports = { buttonCommands };


(async () => {
    try {
        console.log('Started refreshing application (/) commands.');

        await rest.put(
            Routes.applicationCommands(clientId),
            { body: commands },
        );

        console.log('Successfully reloaded application (/) commands.');
    } catch (error) {
        console.error(error);
    }
})();

image of all of my commands for reference: click here

if it's needed, here is also a link to a sourcebin that shows the code for all of these commands and my index.js file: https://srcb.in/mtqWFVLAeN

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

0

module.exports = { buttonCommands };

It looks like here you are only exporting buttonCommands, but not commands.

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