-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeploy-commands.js
107 lines (100 loc) · 3.61 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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
const { discordMessage, warnMessage, errorMessage } = require('./src/functions/logger.js');
const { generateID } = require('./src/functions/helper.js');
const { REST, Routes } = require('discord.js');
const config = require('./config.json');
const path = require('path');
const fs = require('fs');
function deployCommands() {
const commands = [];
let skipped = 0;
const foldersPath = path.join(__dirname, 'src/commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
if (folder == 'dev') continue;
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter((file) => file.endsWith('.js'));
for (const file of commandFiles) {
if (file.toLowerCase().includes('disabled')) {
skipped++;
continue;
}
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
warnMessage(`The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
const rest = new REST().setToken(config.discord.token);
(async () => {
try {
discordMessage(
`Started refreshing ${commands.length} application (/) commands and skipped over ${skipped} commands.`
);
const data = await rest.put(
Routes.applicationCommands(Buffer.from(config.discord.token.split('.')[0], 'base64').toString('ascii')),
{
body: commands,
}
);
discordMessage(
`Successfully reloaded ${data.length} application (/) commands and skipped over ${skipped} commands.`
);
} catch (error) {
var errorId = generateID(config.other.errorIdLength);
errorMessage(`Error ID: ${errorId}`);
errorMessage(error);
}
})();
}
function deployDevCommands() {
const commands = [];
let skipped = 0;
const foldersPath = path.join(__dirname, 'src/commands');
const commandFolders = fs.readdirSync(foldersPath);
for (const folder of commandFolders) {
if (folder != 'dev') continue;
const commandsPath = path.join(foldersPath, folder);
const commandFiles = fs.readdirSync(commandsPath).filter((file) => file.endsWith('.js'));
for (const file of commandFiles) {
if (file.toLowerCase().includes('disabled')) {
skipped++;
continue;
}
const filePath = path.join(commandsPath, file);
const command = require(filePath);
if ('data' in command && 'execute' in command) {
commands.push(command.data.toJSON());
} else {
warnMessage(`The command at ${filePath} is missing a required "data" or "execute" property.`);
}
}
}
const rest = new REST().setToken(config.discord.token);
(async () => {
try {
discordMessage(
`Started refreshing ${commands.length} application (/) commands to the dev server and skipped over ${skipped} commands.`
);
const data = await rest.put(
Routes.applicationGuildCommands(
Buffer.from(config.discord.token.split('.')[0], 'base64').toString('ascii'),
config.discord.devServer
),
{
body: commands,
}
);
discordMessage(
`Successfully reloaded ${data.length} application (/) commands to the dev server and skipped over ${skipped} commands.`
);
} catch (error) {
var errorId = generateID(config.other.errorIdLength);
errorMessage(`Error ID: ${errorId}`);
errorMessage(error);
}
})();
}
module.exports = { deployCommands, deployDevCommands };