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

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

0

module.exports = { buttonCommands };

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

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