-
Notifications
You must be signed in to change notification settings - Fork 1
/
deploy-commands.js
81 lines (69 loc) · 2.02 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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
require("dotenv").config();
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const fs = require("fs");
const commands = [];
const commandFiles = fs
.readdirSync("./commands")
.filter((file) => file.endsWith(".js"));
const local = process.argv.includes("--local") || process.argv.includes("-l");
const del = process.argv.includes("--delete") || process.argv.includes("-d");
const global = process.argv.includes("--global") || process.argv.includes("-g");
const test = process.argv.includes("--test") || process.argv.includes("-t");
// Place your client and guild ids here
const guildId = process.env.GUILD_ID;
let clientId;
let token;
if (test) {
clientId = process.env.TESTCLIENT_ID;
token = process.env.TESTTOKEN;
}
else {
clientId = process.env.CLIENT_ID;
token = process.env.TOKEN;
}
for (const file of commandFiles) {
const command = require(`./commands/${file}`);
commands.push(command.data.toJSON());
}
const rest = new REST({ version: "9" }).setToken(token);
(async () => {
if (global) {
try {
console.log(
"Started refreshing application (/) commands for global guilds."
);
await rest.put(
Routes.applicationCommands(clientId),
{ body: commands }
);
console.log(
"Successfully reloaded application (/) commands for global guilds."
);
}
catch (error) {
console.error(error);
}
}
else if (local) {
try {
console.log(
"Started refreshing application (/) commands for test guild."
);
await rest.put(Routes.applicationGuildCommands(clientId, guildId), {
body: commands,
});
console.log(
"Successfully reloaded application (/) commands for test guild."
);
}
catch (error) {
console.error(error);
}
}
else if (del) {
rest.put(Routes.applicationGuildCommands(clientId, guildId), { body: [] })
.then(() => console.log('Successfully deleted all guild commands.'))
.catch(console.error);
}
})();