-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.js
More file actions
61 lines (52 loc) · 2.03 KB
/
deploy.js
File metadata and controls
61 lines (52 loc) · 2.03 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
function refresh() {
const { REST, Routes, SlashCommandBuilder, PermissionFlagsBits } = require('discord.js');
const { clientId, guildIds, token } = require('./config.json');
const fs = require('node:fs');
const path = require('node:path');
const JSON5 = require('json5');
require('json5/lib/register');
const { commands } = require('./triggers.json5');
const commandData = [];
const builtCommands = []
commands.forEach(function (command, index) {
if (Array.isArray(command.name)) {
command.name.forEach((name, index) => {
builtCommands.push({
data: new SlashCommandBuilder()
.setName(name)
.setDescription(command.description)
});
})
} else {
builtCommands.push({
data: new SlashCommandBuilder()
.setName(command.name)
.setDescription(command.description)
});
}
});
builtCommands.push({data: new SlashCommandBuilder()
.setName("refresh")
.setDescription("Refreshes all commands of the bot")
.setDefaultMemberPermissions(PermissionFlagsBits.Administrator)})
builtCommands.forEach(function (builtCommand, index) {
commandData.push(builtCommand.data);
});
const rest = new REST().setToken(token);
(async () => {
try {
for (const guildId of guildIds) {
console.log(`Starting refresh for Guild ${guildId}.`)
console.log(`Started refreshing ${builtCommands.length} application (/) commands.`);
const data = await rest.put(
Routes.applicationGuildCommands(clientId, guildId),
{ body: commandData },
);
console.log(`Successfully reloaded ${data.length} application (/) commands.\n`);
}
} catch (error) {
console.error(error);
}
})();
}
module.exports.refresh = refresh;