-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
52 lines (42 loc) · 1.37 KB
/
index.js
File metadata and controls
52 lines (42 loc) · 1.37 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
50
51
52
require("dotenv").config();
const { Collection, Client, EmbedBuilder, WebhookClient, ChannelType } = require("discord.js");
const color = require("colors");
const { loadSlashCommands } = require("./Src/Handlers/Load/slashCommand");
const { loadEvents } = require("./Src/Handlers/Load/event");
const { loadAntiCrash } = require("./Src/Handlers/antiCrash");
const clientSettingsObject = require("./Src/Functions/clientSettingsObject");
const config = require("./config");
(async () => {
try {
// Create the Discord client
client = new Client(clientSettingsObject());
[
"slashCommands",
"messageCommands",
"events",
"categories",
"cooldowns",
].forEach((prop) => (client[prop] = new Collection()));
// Crash handlers & event loader
loadAntiCrash(client, color);
loadEvents(client, color);
// Log in to Discord
await client.login(process.env.TOKEN);
// Register Slash commands
loadSlashCommands(client, color);
} catch (error) {
console.error("❌ Startup error:", error);
}
// Graceful shutdown
const shutdown = async () => {
console.log("🛑 Shutting down gracefully...".yellow);
// Destroy Discord client
if (client) {
client.removeAllListeners();
await client.destroy();
}
process.exit(0);
};
process.on("SIGINT", shutdown);
process.on("SIGTERM", shutdown);
})();