-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-commands.js
51 lines (45 loc) · 1.48 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
41
42
43
44
45
46
47
48
49
50
51
/* eslint-disable max-len */
/* eslint-disable no-tabs */
/* eslint-disable no-inline-comments */
// Logger Settings
const logger = require("node-color-log");
logger.setLevel("info");
logger.setDate(() => (new Date()).toLocaleString());
// Setting Configutation
const dotenv = require("dotenv");
dotenv.config();
// Module Import
const fs = require("fs");
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
// initialize empty container
const commands = [];
// Read files
const commandFolders = fs.readdirSync("./commands");
logger.debug("⏳ Collecting command files ...");
for (const folder of commandFolders) {
logger.debug(`⏳ Reading folder ${folder}'s command files...`);
const commandFiles = fs.readdirSync(`./commands/${folder}`).filter((file) => file.endsWith(".js"));
for (const file of commandFiles) {
logger.debug(`⏳ Reading file ${file} for command...`);
const command = require(`./commands/${folder}/${file}`);
logger.debug(`✔️ ${folder}.${file} read!`);
commands.push(command.data.toJSON());
}
}
logger.debug("✔️ Command files collected!");
// Deploy
const rest = new REST({ version: "9" }).setToken(process.env.TOKEN);
(async () => {
try {
logger.debug("Started refreshing application (/) commands.");
await rest.put(
Routes.applicationCommands(process.env.ClientId),
{ body: commands },
);
logger.debug("Successfully reloaded application (/) commands.");
}
catch (error) {
logger.error(error);
}
})();