-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathmain.ts
47 lines (40 loc) · 1.32 KB
/
main.ts
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
//@ts-ignore
import config from "./config.json" assert { type: "json" };
import { Client, Collection, GatewayIntentBits } from "discord.js";
import fs from "node:fs";
declare module "discord.js" {
interface Client {
commands: Collection<unknown, any>
}
}
// Create a new client
const client = new Client({
intents: [
GatewayIntentBits.Guilds,
GatewayIntentBits.GuildMessages,
GatewayIntentBits.GuildMembers,
GatewayIntentBits.DirectMessages,
GatewayIntentBits.MessageContent
],
});
// Read command files
client.commands = new Collection();
const commandFiles = fs.readdirSync("./build/commands").filter(file => file.endsWith(".js"));
// Retrieving all the command files
for (const file of commandFiles) {
const { command } = await import(`./commands/${file}`);
client.commands.set(command.data.name, command);
}
// Read event files
const eventFiles = fs.readdirSync("./build/events").filter(file => file.endsWith(".js"));
// Retrieving all the event files
for (const file of eventFiles) {
const { event } = await import(`./events/${file}`);
if (event.once) {
client.once(event.name, (...args) => event.execute(...args));
} else {
client.on(event.name, (...args) => event.execute(...args));
}
}
// Login to Discord
client.login(config.token);