TypeError: Cannot read properties of undefined (reading 'toJSON') #8419
-
Which package is this bug report for?discord.js Issue descriptionI'm using the Discord.js guide for slash commands, and i'm getting this error: Code sampleconst { REST } = require('@discordjs/rest');
const { Routes, Client, GatewayIntentBits } = require('discord.js');
const { token } = require('./config.json');
const fs = require('node:fs');
const client = new Client({ intents: [GatewayIntentBits.Guilds] });
const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
// Place your client and guild ids here
const clientId = 'myclientidisprivatern';
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '10' }).setToken(token);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(clientId),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
client.login(token) Package version14.1.2 Node.js version18.7.0 Operating systemWindows Priority this issue should haveMedium (should be fixed soon) Which partials do you have configured?No Partials Which gateway intents are you subscribing to?No Intents I have tested this issue on a development releaseNo response |
Beta Was this translation helpful? Give feedback.
Answered by
SuperchupuDev
Aug 3, 2022
Replies: 1 comment 1 reply
-
One of your commands doesn't have a |
Beta Was this translation helpful? Give feedback.
1 reply
Answer selected by
kyranet
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
One of your commands doesn't have a
data
property exported. You should make sure no command files are empty and export the command builder asdata