-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-commands.ts
40 lines (35 loc) · 1.17 KB
/
deploy-commands.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
import {
RESTPostAPIChatInputApplicationCommandsJSONBody,
SlashCommandBuilder,
} from "discord.js";
import fs from "fs";
import { REST } from "@discordjs/rest";
import { Routes } from "discord-api-types/v9";
import { env } from "./lib/config";
const commands: RESTPostAPIChatInputApplicationCommandsJSONBody[] = [];
const commandFiles: string[] = fs
.readdirSync("./commands")
.filter((file: string) => file.endsWith(".ts"));
const discordToken = env.get<string>("DISCORD_TOKEN");
const clientId = env.get<string>("BOT_CLIENT_ID");
const rest = new REST({ version: "9" }).setToken(discordToken);
(async () => {
for (const file of commandFiles) {
const command: {
data: SlashCommandBuilder;
} = await import(`./commands/${file}`);
if ("data" in command && "execute" in command) {
commands.push(command.data.toJSON());
}
}
const guildIds = env.get<string[]>("PERSONAL_GUILD_IDS");
for (const guildId of guildIds) {
rest
.put(Routes.applicationGuildCommands(clientId, guildId), {
body: commands,
})
.then(() => console.log("Successfully registered application commands."))
.catch(console.error);
}
})();
export {};