如何在Discord.js中注销/删除斜杠命令



我正在使用Discord.js V13(节点js v16.8.0(,并且想要删除所有注册的全局命令,我正在使用@discordjs/rest模块,但我不确定

这是我的deploy-commands.js文件:

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);
}
})();

要删除所有全局命令,请使用Client.application.commands.set()并传递一个空数组

client.application.commands.set([])

我设法弄清楚了,结果发现你需要把这行代码放在异步函数之间

await rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: commands,
});

最新更新