This repository was archived by the owner on Jul 20, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdeploy-commands.js
More file actions
52 lines (42 loc) · 1.62 KB
/
deploy-commands.js
File metadata and controls
52 lines (42 loc) · 1.62 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
const { REST } = require('@discordjs/rest');
const { Routes } = require('discord-api-types/v10');
if (require.main === module) {
const { readdirSync } = require('node:fs');
const { token, clientId, beta } = require('./config.js');
const commands = [];
for (const folder of readdirSync(`${__dirname}/commands`)) {
for (const file of readdirSync(`${__dirname}/commands/${folder}`).filter(file => file.endsWith(".js"))) {
try {
const command = require(`${__dirname}/commands/${folder}/${file}`);
commands.push(command.data.toJSON());
} catch (err) {
console.error(err);
}
}
}
const contextMenu = [];
for (const folder of readdirSync(`${__dirname}/context menu`)) {
for (const file of readdirSync(`${__dirname}/context menu/${folder}`).filter(file => file.endsWith(".js"))) {
try {
const contextmenu = require(`${__dirname}/context menu/${folder}/${file}`);
contextMenu.push(contextmenu.data.toJSON());
} catch (err) {
console.error(err);
}
}
}
const all = [];
commands.forEach(e => { if (!beta && e.name !== "test" || beta) all.push(e) })
contextMenu.forEach(e => all.push(e));
send(all, token, clientId)
}
async function send(commands, token, clientId) {
const rest = new REST({ version: '10' }).setToken(token);
console.log(`Started refreshing ${commands.length} interaction commands.`);
await rest.put(
Routes.applicationCommands(clientId),
{ body: commands },
).catch(e => { console.error(e) });
console.log(`Successfully reloaded ${commands.length} interaction commands.`);
};
module.exports = { send }