I'm using Discord.js V13 (Node JS v16.8.0) and wanted to delete all registered global commands, I'm using the @discordjs/rest module, but I'm not sure how
Here is my deploy-commands.js file:
const fs = require('fs');
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { clientId, guildId, token } = require('./config.json');
const commands = [];
const commandFiles = fs.readdirSync('./commands').filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: '9' }).setToken(token);
(async () => {
try {
console.log('Started refreshing application (/) commands.');
await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commands },
);
console.log('Successfully reloaded application (/) commands.');
} catch (error) {
console.error(error);
}
})();
To delete all global commands, use Client.application.commands.set() and pass an empty array
client.application.commands.set([])
I managed to figure it out, turns out you need to put this line of code in between the async function
await rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: commands,
});