forked from hemisemidemipresent/cyberquincy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
register.js
71 lines (60 loc) · 2.49 KB
/
register.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
// registers slash commands
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v9');
const { activeToken, activeClientID } = require('./helpers/config');
const { testing, testingGuild } = require('./1/config.json');
const { ApplicationCommandOptionType } = require('discord.js');
async function loadAliases() {
const AliasRepository = require('./alias-repository.js');
global.Aliases = new AliasRepository();
await Aliases.asyncAliasFiles();
}
function addHideOptions(options) {
const hasSubcommand = options.some(
({ type }) =>
type === ApplicationCommandOptionType.SubcommandGroup || type === ApplicationCommandOptionType.Subcommand
);
if (hasSubcommand) options.forEach((option) => ((option.options ??= []), addHideOptions(option.options)));
else
options.push({
name: 'hide',
description: 'Whether to hide the response',
type: ApplicationCommandOptionType.Boolean
});
}
function getCommandBody(file) {
const body = file.data.toJSON();
body.options ??= [];
addHideOptions(body.options);
return body;
}
async function registerCommands() {
await loadAliases();
slashCommandCenter = require('./slash_command_center');
const rest = new REST({ version: '9' }).setToken(activeToken());
if (testing) {
const commands = slashCommandCenter.commandFiles().map(getCommandBody);
await rest
.put(Routes.applicationGuildCommands(activeClientID(), testingGuild), { body: commands })
.then(() => console.log('Successfully registered application commands for test guild.'))
.catch(console.error);
} else {
const commands = slashCommandCenter
.commandFiles()
.filter((file) => !file.beta)
.map(getCommandBody);
await rest
.put(Routes.applicationCommands(activeClientID()), { body: commands })
.then(() => console.log('Successfully registered application commands for all guilds.'))
.catch(console.error);
const betaCommands = slashCommandCenter
.commandFiles()
.filter((file) => file.beta)
.map(getCommandBody);
await rest
.put(Routes.applicationGuildCommands(activeClientID(), testingGuild), { body: betaCommands })
.then(() => console.log('Successfully registered beta commands for test guild.'))
.catch(console.error);
}
}
registerCommands();