-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy-commands.js
More file actions
63 lines (54 loc) · 2.01 KB
/
deploy-commands.js
File metadata and controls
63 lines (54 loc) · 2.01 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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
const { REST, Routes } = require("discord.js");
const fs = require("node:fs");
const path = require("node:path");
const dotenv = require("dotenv");
dotenv.config();
const clientId = process.env.clientId;
const token = process.env.token;
const logLevel = process.env.logLevel;
const Logger = require("node-color-log");
const logger = Logger.createNamedLogger("HuskCat v1");
logger.setDate(() =>
new Date()
.toLocaleString(undefined, {
year: "numeric",
month: "2-digit",
day: "2-digit",
hour: "2-digit",
hour12: false,
minute: "2-digit",
second: "2-digit",
})
.replace(/\//g, "-"),
);
logger.setLevel(logLevel);
const commands = [];
// Grab all the command files from the commands directory you created earlier
const commandRoot = path.join(__dirname, "commands");
for (const commandPath of commandRoot) {
const commandFile = fs.readdirSync(`${commandRoot}/${commandPath}`).filter((file) => file.endsWith(".js"));
for (const commands of commandFile) {
const command = require(`${commandRoot}/${commandPath}/${commands}`);
commands.push(command.data.toJSON());
}
}
// Construct and prepare an instance of the REST module
const rest = new REST({ version: "10" }).setToken(token);
// and deploy your commands!
(async () => {
try {
logger.info("Reseting application (/) commands...");
rest
.put(Routes.applicationCommands(clientId), { body: [] })
.then(() => logger.success("Successfully deleted all application commands."))
.catch((error) => logger.error(error.toString()));
logger.info("Successfully reset application (/) commands!");
logger.info(`Started refreshing ${commands.length} application (/) commands.`);
// The put method is used to fully refresh all commands in the guild with the current set
const data = await rest.put(Routes.applicationCommands(clientId), { body: commands });
logger.success(`Successfully reloaded ${data.length} application (/) commands!`);
} catch (error) {
// And of course, make sure you catch and log any errors!
logger.error(error.toString());
}
})();