-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-commands.ts
44 lines (37 loc) · 1.32 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
41
42
43
44
import { REST, Routes } from "discord.js";
import { readdirSync } from "fs";
import dotenv from "dotenv";
dotenv.config();
const commands: any[] = [];
const commandFiles = readdirSync("./src/commands").filter((file) => file.endsWith(".ts"));
for (const file of commandFiles) {
const command = await import(`./src/commands/${file}`);
console.log(file, "file");
commands.push(command.default.data.toJSON());
console.log(commands);
}
if (process.env.DISCORD_TOKEN === undefined) {
throw new Error("DISCORD_TOKEN is undefined");
}
const rest = new REST({ version: "10" }).setToken(process.env.DISCORD_TOKEN);
(async (env) => {
if (process.env.CLIENT_ID === undefined) {
throw new Error("DISCORD_TOKEN is undefined");
}
if (process.env.GUILD_ID === undefined) {
throw new Error("GUILD_ID is undefined");
}
try {
console.log("Started refreshing application (/) commands.");
if (env === "production") {
console.log("Started refreshing guild (/) commands.");
await rest.put(Routes.applicationGuildCommands(process.env.CLIENT_ID, process.env.GUILD_ID), {
body: commands,
});
}
await rest.put(Routes.applicationCommands(process.env.CLIENT_ID), { body: commands });
console.log("Successfully reloaded application (/) commands.");
} catch (error) {
console.error(error);
}
})();