-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathindex.js
More file actions
93 lines (80 loc) Β· 2.89 KB
/
index.js
File metadata and controls
93 lines (80 loc) Β· 2.89 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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
const config = require("./config.js");
const mongoose = require("mongoose");
const { readdir } = require("fs").promises;
const Client = require("./Base/Client.js");
const client = new Client();
// creating an empty array for registering slash commands
client.register_arr = [];
const init = async () => {
/* Load all slash commands */
const commandFolders = await readdir("./commands/");
for (const dir of commandFolders) {
const commandFiles = await readdir(`./commands/${dir}/`);
for (const file of commandFiles) {
if (!file.endsWith(".js")) continue;
const props = require(`./commands/${dir}/${file}`);
const commandName = file.split(".")[0];
client.interactions.set(commandName, {
name: commandName,
...props,
});
// Filter properties for registration
client.register_arr.push({
name: commandName,
description: props.description,
options: props.options,
defaultPermission: props.default_permission,
type: props.type,
});
client.log(`[π] Command loaded: ${commandName}!`, "cmd");
}
}
/* Load discord events */
const discordEvents = await readdir("./events/discord");
for (const file of discordEvents) {
if (!file.endsWith(".js")) continue;
const event = require(`./events/discord/${file}`);
const eventName = file.split(".")[0];
client.log(`(π) Event loaded : ${eventName} !`, "event");
client.on(eventName, (...args) => event(client, ...args));
// Note: Deleting cache is usually only needed for hot-reloading
}
/* Load Giveaway events */
const giveawayEvents = await readdir("./events/giveaways");
for (const file of giveawayEvents) {
if (!file.endsWith(".js")) continue;
const event = require(`./events/giveaways/${file}`);
const eventName = file.split(".")[0];
client.log(`(π) Giveaway event loaded : ${eventName} !`, "event");
client.manager.on(eventName, (...args) => event(client, ...args));
}
// Connect to mongoose database
mongoose.set("strictQuery", false);
try {
await mongoose.connect(config.mongoDB, {
serverSelectionTimeoutMS: 30000,
connectTimeoutMS: 30000,
});
client.log("Connected to the Mongodb database.", "done");
} catch (err) {
client.log(
`Unable to connect to the Mongodb database. Error: ${err}`,
"error"
);
}
// Login to bot
await client.login(config.token);
};
init();
client
.on("disconnect", () => client.log("Bot is disconnecting...", "warn"))
.on("reconnecting", () => client.log("Bot reconnecting...", "log"))
.on("error", (e) => client.log(e, "error"))
.on("warn", (info) => client.log(info, "warn"));
// For any unhandled errors
process.on("unhandledRejection", (err) => {
client.log(`Unhandled Rejection: ${err.stack}`, "error");
});
process.on("uncaughtException", (err) => {
client.log(`Uncaught Exception: ${err.stack}`, "error");
});