Error

// Place your client and guild ids here
const clientId = clientID;
const guildId = guildID;
const foldersPath = path.join(__dirname, 'Commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
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);
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ('data' in command && 'executeInteraction' in command) {
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// ---> Rest for slash commands
const rest = new REST({ version: '10' }).setToken(token);

(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// ---> The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {

// ---> And of course, make sure you catch and log any errors!
console.error(error);
}
})();
// Place your client and guild ids here
const clientId = clientID;
const guildId = guildID;
const foldersPath = path.join(__dirname, 'Commands');
const commandFolders = fs.readdirSync(foldersPath);

for (const folder of commandFolders) {
const commandsPath = path.join(foldersPath, folder);
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);
// Set a new item in the Collection with the key as the command name and the value as the exported module
if ('data' in command && 'executeInteraction' in command) {
client.commands.set(command.data.name, command);
commands.push(command.data.toJSON());
} else {
console.log(`[WARNING] The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}

// ---> Rest for slash commands
const rest = new REST({ version: '10' }).setToken(token);

(async () => {
try {
console.log(`Started refreshing ${commands.length} application (/) commands.`);

// ---> The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(
Routes.applicationGuildCommands(clientId),
{ body: commands },
);

console.log(`Successfully reloaded ${data.length} application (/) commands.`);
} catch (error) {

// ---> And of course, make sure you catch and log any errors!
console.error(error);
}
})();
4 Replies
d.js toolkit
d.js toolkit16mo ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Duff
Duff16mo ago
Squid
Squid16mo ago
If you want global commands, use
Routes.applicationCommands(clientId),
Routes.applicationCommands(clientId),
If you want guild commands, use
Routes.applicationGuildCommands(clientId, guildId),
Routes.applicationGuildCommands(clientId, guildId),
They are different routes, not just different parameters
Duff
Duff16mo ago
Yea just found it God i feel dumb lmao But thanks man!