-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-commands.ts
53 lines (41 loc) · 1.23 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
45
46
47
48
49
50
51
52
53
import { REST, Routes } from "discord.js";
import dotenv from "dotenv";
import fs from "node:fs";
import path from "path";
if (fs.existsSync(".env")) {
dotenv.config();
}
const commands = [];
const commandsPath = path.join(__dirname, "src", "commands");
const commandFiles = fs.readdirSync(commandsPath);
for (const file of commandFiles) {
const command = require(`./src/commands/${file}`).default;
commands.push(command.data.toJSON());
}
const token = process.env.DISCORD_APP_TOKEN;
const clientId = process.env.DISCORD_CLIENT_ID;
if (!token) {
console.error("No token provided. Exiting...");
process.exit(1);
}
if (!clientId) {
console.error("No client ID provided. Exiting...");
process.exit(1);
}
const rest = new REST({ version: "10" }).setToken(token);
(async () => {
try {
console.log("Started refreshing application (/) commands.");
console.log("Deleting old commands...");
await rest.put(Routes.applicationCommands(clientId), {
body: [],
});
console.log("Registering new commands...");
await rest.put(Routes.applicationCommands(clientId), {
body: commands,
});
console.log("Successfully reloaded application (/) commands.");
} catch (error) {
console.error(error);
}
})();