41 lines
1.3 KiB
TypeScript
41 lines
1.3 KiB
TypeScript
|
// https://discordjs.guide/creating-your-bot/command-deployment.html#guild-commands
|
||
|
|
||
|
import { REST, RESTGetAPIOAuth2CurrentApplicationResult, RESTPostAPIApplicationCommandsJSONBody, Routes } from "discord.js";
|
||
|
import config from "../config";
|
||
|
import requireDirectory from "require-directory";
|
||
|
|
||
|
import Command from "../command";
|
||
|
|
||
|
const post: RESTPostAPIApplicationCommandsJSONBody[] = [];
|
||
|
|
||
|
const guildId = process.argv.slice(2)[0];
|
||
|
requireDirectory<{default: Command}, void>(module, "../commands", {
|
||
|
visit: function (obj) {
|
||
|
console.log(obj);
|
||
|
// eslint-disable-next-line @typescript-eslint/ban-ts-comment
|
||
|
// @ts-ignore
|
||
|
post.push(new obj.default().toRESTPostApplicationCommands());
|
||
|
},
|
||
|
});
|
||
|
|
||
|
const rest = new REST().setToken(config.tokens.Discord);
|
||
|
|
||
|
(async () => {
|
||
|
const me = await rest.get(Routes.oauth2CurrentApplication()) as RESTGetAPIOAuth2CurrentApplicationResult;
|
||
|
console.log(`Started refreshing ${post.length} application commands.`);
|
||
|
if (guildId && guildId != "")
|
||
|
await rest.put(
|
||
|
Routes.applicationGuildCommands(me.id, guildId),
|
||
|
{ body: post },
|
||
|
);
|
||
|
else {
|
||
|
await rest.put(
|
||
|
Routes.applicationCommands(me.id),
|
||
|
{ body: post },
|
||
|
);
|
||
|
}
|
||
|
console.log("Refreshed successfully");
|
||
|
})().catch( e => {
|
||
|
console.error(e);
|
||
|
});
|