-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommands.js
More file actions
77 lines (64 loc) · 2 KB
/
commands.js
File metadata and controls
77 lines (64 loc) · 2 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
const { glob } = require("glob"),
{ promisify } = require("util"),
globPromise = promisify(glob);
const { REST } = require("@discordjs/rest");
const { Routes } = require("discord-api-types/v9");
const fs = require("node:fs");
require("dotenv").config();
module.exports = async (client) => {
// apps
const appFiles = await globPromise(`${process.cwd()}/apps/*.js`);
appFiles.map((value) => require(value));
// Slash Commands
const slashCommands = await globPromise(
`${process.cwd()}/SlashCommands/*.js`
);
const arrayOfSlashCommands = [];
slashCommands.map((value) => {
const file = require(value);
if (!file?.name) return;
client.commands.set(file.name, file);
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
arrayOfSlashCommands.push(file);
});
const rest = new REST({ version: "9" }).setToken(process.env.HTTP_TOKEN);
(async () => {
try {
console.log("Started refreshing application (/) commands.");
await rest.put(Routes.applicationCommands(process.env.HTTP_ID), {
body: client.commands,
});
console.log("Successfully reloaded application (/) commands.");
} catch (error) {
console.error(error);
}
})();
// Buttons
const buttonFiles = await globPromise(`${process.cwd()}/buttons/**/*.js`);
buttonFiles.map((value) => {
const file = require(value);
const splitted = value.split("/");
const directory = splitted[splitted.length - 2];
if (file.name) {
const properties = {
directory,
...file,
};
client.buttons.set(file.name, properties);
}
});
// modals
const modalFiles = await globPromise(`${process.cwd()}/modals/**/*.js`);
modalFiles.map((value) => {
const file = require(value);
const splitted = value.split("/");
const directory = splitted[splitted.length - 2];
if (file.name) {
const properties = {
directory,
...file,
};
client.modals.set(file.name, properties);
}
});
};