-
Notifications
You must be signed in to change notification settings - Fork 0
/
deploy-commands.js
40 lines (31 loc) · 1.04 KB
/
deploy-commands.js
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 { REST, Routes } from "discord.js";
import dotenv from 'dotenv';
import fs from 'node:fs';
import path from 'node:path';
import { fileURLToPath } from 'node:url';
dotenv.config();
const { TOKEN, CLIENT_ID } = process.env;
const __dirname = path.dirname(fileURLToPath(import.meta.url));
const commandsPath = path.join(__dirname, "commands");
const commandsFiles = fs.readdirSync(commandsPath).filter(file => file.endsWith(".js"));
const commands = [];
for (const file of commandsFiles) {
const filePath = `./commands/${file}`;
const commandModule = await import(filePath);
commands.push(commandModule.default.data.toJSON());
}
// REST instance
const rest = new REST({ version: "10" }).setToken(TOKEN);
// Deploy
(async () => {
try {
console.log(`Restarting ${commands.length} commands...`);
await rest.put(
Routes.applicationCommands(CLIENT_ID),
{ body: commands }
);
console.log("Commands registered successfully!");
} catch (error) {
console.error(error);
}
})();