-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup.js
63 lines (51 loc) · 1.87 KB
/
setup.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
// This script registers the bot's application commands.
// Command line arguments:
// 1. The ID of the bot (required).
// 2. The ID of the guild to register the commands in; nothing/empty to register commands globally.
// 3. Set this to "delete" to instead delete all registered commands, rather than registering new ones.
const log = require("./src/log.js");
if (!process.argv[2]) {
log("Please specify the application ID of your Discord bot as a command line argument (can be found at https://discordapp.com/developers/applications)");
return;
}
const auth = require("./auth.json");
if (!auth.bottoken || auth.bottoken == "CENSORED") {
log("Please fill in the token of your Discord bot (can be found at https://discordapp.com/developers/applications).");
return;
}
const { REST } = require("@discordjs/rest");
const rest = new REST({ version: '10' }).setToken(auth.bottoken);
var path;
if (process.argv[3]) {
path = `/applications/${process.argv[2]}/guilds/${process.argv[3]}/commands`;
}
else {
path = `/applications/${process.argv[2]}/commands`;
}
if (process.argv[4] == "delete") {
log("All modules loaded; deleting commands.");
rest.get(path).then(response => {
log(response.length + " commands found to delete.");
for (var i = 0; i < response.length; i++) {
let { id, name } = response[i];
rest.delete(`${path}/${id}`).then(() => log(`Deleted command ${id} (${name})`), log);
}
}, log);
}
else {
const commands = require("./src/commands.js");
const list = commands.options.filter(command => !command.isTextOnly);
log(`All modules loaded; registering ${list.length} commands.`);
rest.put(path, { body: list }).then(
response => {
log("Success! Registered commands:");
for (var i = 0; i < response.length; i++) {
log(`/${response[i].name} (id ${response[i].id}, version ${response[i].version})`);
}
},
error => {
log("Failed.");
log(error);
}
);
}