forked from Adivise/NanoLab
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploySlash.js
57 lines (44 loc) · 2.19 KB
/
deploySlash.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
const { plsParseArgs } = require('plsargs');
const argv = plsParseArgs(process.argv.slice(2));
const path = require("path");
const { TOKEN } = require("./settings/config.js");
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { readdirSync } = require('fs');
(async () => {
let publishMode = argv.get(0) == "guild" ? "guild" : argv.get(0) == "global" ? "global" : null;
if (!publishMode) {
console.error(`Invalid sharing mode! Valid modes: guild, global`);
console.error(`Usage example: node deploySlash.js guild <guildId>`);
console.error(`Usage example: node deploySlash.js global`);
return process.exit(1);
}
const commands = [];
readdirSync("./commands/").map(async dir => {
readdirSync(`./commands/${dir}`).map(async (cmd) => {
commands.push(require(path.join(__dirname, `./commands/${dir}/${cmd}`)));
})
})
const rest = new REST({ version: "9" }).setToken(TOKEN);
console.info("Retrieving account information!");
/** @type {import("discord-api-types/rest/v9/user").RESTGetAPIUserResult} */
const client = await rest.get(Routes.user());
console.info(`Account information received! ${client.username}#${client.discriminator} (${client.id})`);
console.info(`Slash (Application) are deployed on discord!`);
switch (publishMode) {
case "guild": {
let guildId = argv.get(1);
console.info(`Sharing mode: server (${guildId})`);
await rest.put(Routes.applicationGuildCommands(client.id, guildId), { body: commands });
console.info(`Slash commands may take 3-5 seconds to arrive.`);
break;
}
case "global": {
console.info(`Sharing mode: global`);
await rest.put(Routes.applicationCommands(client.id), { body: commands });
console.info(`Slash commands can take up to 1 hour to arrive. If you want it to come immediately, you can throw your bot from your server and get it back.`);
break;
}
}
console.info(`Slash (Application) deployed!`);
})();