-
Notifications
You must be signed in to change notification settings - Fork 20
Expand file tree
/
Copy pathindex.js
More file actions
49 lines (39 loc) · 1.38 KB
/
index.js
File metadata and controls
49 lines (39 loc) · 1.38 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
import { config } from 'dotenv';
import { readdir } from 'fs/promises';
import { Client, GatewayIntentBits, Collection } from 'discord.js';
config();
const client = new Client({
intents: [GatewayIntentBits.Guilds],
rest: { timeout: 30000 }
});
const commands = [];
client.commands = new Collection();
const loadCommands = async () => {
const commandFolders = await readdir('./commands');
await Promise.all(commandFolders.map(async (folder) => {
const commandFiles = await readdir(`./commands/${folder}`);
await Promise.all(commandFiles.map(async (file) => {
const command = await import(`./commands/${folder}/${file}`);
client.commands.set(command.default.data.name, command.default);
if (command.default.data.name !== 'help') {
commands.push(command.default.data.toJSON());
}
}));
}));
}
const loadEvents = async () => {
const eventFolders = await readdir('./events');
await Promise.all(eventFolders.map(async (folder) => {
const eventFiles = await readdir(`./events/${folder}`);
await Promise.all(eventFiles.map(async (file) => {
const event = await import(`./events/${folder}/${file}`);
client.on(event.default.name, (...args) => event.default.execute(...args));
}));
}));
}
(async () => {
await loadCommands();
await loadEvents();
await client.login(process.env.token);
}) ()
export default { client, commands };