-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.ts
46 lines (37 loc) · 1.18 KB
/
index.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
import { readdirSync } from "fs";
import { Collection, DiscordAPIError, GatewayIntentBits } from "discord.js";
import { env } from "../environment";
import { DiscordClient } from "./classes/discord";
import Exception from "./exceptions/Exception";
const client = new DiscordClient({
intents: [GatewayIntentBits.Guilds],
});
client.commands = new Collection();
const eventFiles = readdirSync("./src/events").filter(
(file: any) => file.endsWith(".ts") || file.endsWith(".js")
);
for (const file of eventFiles) {
const eventName = file.split(".")[0];
const event = require(`./events/${file}`);
if (event.once) {
client.once(eventName, (...args) => event.execute(client, ...args));
} else {
client.on(eventName, (...args) => event.execute(client, ...args));
}
}
process.on("SIGINT", () => {
client.destroy();
process.exit(0);
});
client.login(env.DISCORD_API_KEY).catch((reason: any) => {
throw new Exception(
"Discord API Connection Failed",
reason instanceof Exception || reason instanceof DiscordAPIError
? reason
: new Exception(reason)
);
});
client.on("ready", () => {
console.log(`Logged in as ${client.user.tag}!`);
});
module.exports = client;