[英]How to unregister/delete a slash command in Discord.js
我正在使用Discord.js V13 (Node 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([])
我設法弄明白了,原來你需要把這行代碼放在異步 function 之間
await rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: commands,
});
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.