-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
57 lines (50 loc) · 1.81 KB
/
index.js
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
/**
* @INFO
* Loading all needed File Information Parameters
*/
const config = require("./config.js"),
Client = require("./Base/Client"),
client = new Client(),
mongoose = require("mongoose"),
{ readdir } = require("fs");
readdir("./events/", (_err, files) => {
files.forEach((file) => {
if (!file.endsWith(".js")) return;
const event = require(`./events/${file}`);
const eventName = file.split(".")[0];
client.logger.log(`(👌) Event loaded : ${eventName} !`, "event");
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/${file}`)];
});
});
readdir("./commands/", (err, files) => {
files.forEach((dir) => {
readdir(`./commands/${dir}/`, (err, cmd) => {
cmd.forEach(file => {
if (!file.endsWith(".js")) return;
const props = require(`./commands/${dir}/${file}`);
const commandName = file.split(".")[0];
client.commands.set(commandName, props);
client.logger.log(`[📕] Command loaded: ${commandName}!`, "cmd");
});
});
});
});
//Connect to mongoose database
mongoose.connect(config.mongoDB, { useNewUrlParser: true, useUnifiedTopology: true, useFindAndModify: false }).then(() => {
//If it connects log the following
client.logger.log("Connected to the Mongodb database.", "log");
}).catch((err) => {
//If it doesn't connect log the following
client.logger.log("Unable to connect to the Mongodb database. Error:" + err, "error");
});
// Login to bot
client.login(config.token);
client.on("disconnect", () => client.logger.log("Bot is disconnecting...", "warn"))
.on("reconnecting", () => client.logger.log("Bot reconnecting...", "log"))
.on("error", (e) => client.logger.log(e, "error"))
.on("warn", (info) => client.logger.log(info, "warn"));
//For any unhandled errors
process.on("unhandledRejection", (err) => {
console.error(err);
});