-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhandler.js
64 lines (59 loc) · 1.87 KB
/
handler.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
const { glob } = require("glob");
const { promisify } = require("util");
const globPromise = promisify(glob);
module.exports = async (client) => {
//Slash Command Hanlder
const slashCommands = await globPromise(
`${process.cwd()}/SlashCommands/*/*.js`
);
const arrayOfSlashCommands = [];
slashCommands.map((value) => {
const file = require(value);
if (!file?.name) return;
client.slashCommands.set(file.name, file);
if (["MESSAGE", "USER"].includes(file.type)) delete file.description;
if (file.userPermissions) file.defaultPermission = false;
arrayOfSlashCommands.push(file);
});
client.on("ready", async () => {
client.guilds.cache
.get(client.config.server)
.commands.set(arrayOfSlashCommands)
.catch((e) => {
console.log(e);
return;
});
});
//Command Handler
const commandfiles = await globPromise(`${process.cwd()}/commands/**/*.js`);
commandfiles.map((value) => {
const file = require(value);
const splitted = value.split("/");
const directory = splitted[splitted.length - 2];
if (file.name) {
const properties = {
directory,
...file,
};
client.commands.set(file.name, properties);
}
if (file.aliases && Array.isArray(file.aliases)) {
file.aliases.forEach((alias) => client.aliases.set(alias, file.name));
}
});
//Event Handler
const eventfiles = await globPromise(`${process.cwd()}/events/*.js`);
eventfiles.map((value) => require(value));
//Button Handler
const btnsf = await globPromise(`${process.cwd()}/buttons/**/*.js`);
btnsf.map((value) => {
const file = require(value);
if (!file?.id) return;
client.btns.set(file.id, file);
});
client.on("interactionCreate", async (interaction) => {
if (interaction.isButton()) {
client.btns.get(interaction.customId)?.run(client, interaction);
}
});
};