-
Notifications
You must be signed in to change notification settings - Fork 1
/
loader.js
54 lines (47 loc) · 1.91 KB
/
loader.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
const { glob } = require("glob");
const { promisify } = require("util");
const globPromise = promisify(glob);
const path = require("path"); // Path
const fs = require("fs"); // File System
const { Client, GatewayIntentBits, Partials, Collection, Discord } = require("discord.js"); // Discord.js V14
const config = require("./config.js"); // Config
module.exports = function(client) {
client.discord = Discord;
client.commands = new Collection();
client.slashCommands = new Collection();
client.on("interactionCreate", async (interaction) => {
if (interaction.isCommand()) {
const command = client.slashCommands.get(interaction.commandName);
if (!command) return interaction.followUp({ content: 'an Erorr' });
const args = [];
for (let option of interaction.options.data) {
if (option.type === 'SUB_COMMAND') {
if (option.name) args.push(option.name);
option.options?.forEach(x => {
if (x.value) args.push(x.value);
});
} else if (option.value) args.push(option.value);
} try {
command.run(client, interaction, config)
} catch (e) {
interaction.followUp({ content: e.message });
}
}
});
handler(client);
async function handler(client) {
const slashCommands = await globPromise(
`${process.cwd()}/commands/*.js`
);
const arrayOfSlashCommands = [];
slashCommands.map((value) => {
const file = require(value);
if (!file.name) return;
client.slashCommands.set(file.name, file);
arrayOfSlashCommands.push(file);
});
client.on("ready", async () => {
await client.application.commands.set(arrayOfSlashCommands).catch(console.error);
});
}
}