const { REST, Routes } = require('discord.js'); const { clientId, token } = require('./config.json'); const fs = require('node:fs'); const commands = []; const contextmenus = []; // Grab all the command files from the commands directory you created earlier const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js')); const contextmenuFiles = fs.readdirSync('./contextmenus').filter(file => file.endsWith('.js')); // Grab the SlashCommandBuilder#toJSON() output of each command's data for deployment for (const file of commandFiles) { const command = require(`./commands/${file}`); commands.push(command.data.toJSON()); } for (const file of contextmenuFiles) { const contextmenu = require(`./contextmenus/${file}`); contextmenus.push(contextmenu.data.toJSON()); } // Construct and prepare an instance of the REST module const rest = new REST().setToken(token); // for deleting global commands rest.delete(Routes.applicationCommands(clientId, '1058857079101739048')) .then(() => console.log('Successfully deleted all application commands.')) .catch(console.error); rest.delete(Routes.applicationCommands(clientId, '1058826316897595502')) .then(() => console.log('Successfully deleted all application commands.')) .catch(console.error); rest.delete(Routes.applicationCommands(clientId, '1058826316897595503')) .then(() => console.log('Successfully deleted all application commands.')) .catch(console.error); rest.delete(Routes.applicationCommands(clientId, '1058826316897595504')) .then(() => console.log('Successfully deleted all application commands.')) .catch(console.error); // and deploy your commands! (async () => { try { console.log(`Started refreshing ${contextmenus.length} context menu commands.`); // The put method is used to fully refresh all commands in the guild with the current set const data = await rest.put( Routes.applicationCommands(clientId), { body: contextmenus }, ); console.log(`Successfully reloaded ${data.length} context menu commands.`); console.log(`Started refreshing ${commands.length} slash commands.`); // The put method is used to fully refresh all commands in the guild with the current set const data1 = await rest.put( Routes.applicationCommands(clientId), { body: commands }, ); console.log(`Successfully reloaded ${data1.length} slash commands.`); } catch (error) { // And of course, make sure you catch and log any errors! console.error(error); } })();