-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-commands.js
More file actions
45 lines (34 loc) · 1.04 KB
/
deploy-commands.js
File metadata and controls
45 lines (34 loc) · 1.04 KB
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
require("dotenv").config();
const fs = require("fs");
const path = require("path");
const { REST, Routes } = require("discord.js");
const commands = [];
const commandsPath = path.join(__dirname, "commands");
function loadCommands(dir) {
const files = fs.readdirSync(dir);
for (const file of files) {
const fullPath = path.join(dir, file);
if (fs.lstatSync(fullPath).isDirectory()) {
loadCommands(fullPath);
} else if (file.endsWith(".js")) {
const command = require(fullPath);
if (command.data) {
commands.push(command.data.toJSON());
}
}
}
}
loadCommands(commandsPath);
const rest = new REST({ version: "10" }).setToken(process.env.TOKEN);
(async () => {
try {
console.log("🔄 Deploying slash commands...");
await rest.put(
Routes.applicationCommands(process.env.CLIENT_ID),
{ body: commands }
);
console.log(`✅ Successfully deployed ${commands.length} commands.`);
} catch (error) {
console.error(error);
}
})();