-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathindex.js
78 lines (69 loc) · 2.5 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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
const config = require("./config.js"),
mongoose = require("mongoose"),
{ readdir } = require("fs"),
Client = require("./base/Client"),
client = new Client();
// creating an empty array for registering slash commands
client.register_arr = []
/* Load all slash commands */
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.interactions.set(commandName, {
name: commandName,
...props
});
client.register_arr.push(props)
client.log(`[📕] Command loaded: ${commandName}!`, "cmd");
});
});
});
});
/* Load discord events */
readdir("./events/discord", (_err, files) => {
files.forEach((file) => {
if (!file.endsWith(".js")) return;
const event = require(`./events/discord/${file}`);
const eventName = file.split(".")[0];
client.log(`(👌) Event loaded : ${eventName} !`, "event");
client.on(eventName, event.bind(null, client));
delete require.cache[require.resolve(`./events/discord/${file}`)];
});
});
/* Load Giveaway events */
readdir("./events/giveaways", (_err, files) => {
files.forEach((file) => {
if (!file.endsWith(".js")) return;
const event = require(`./events/giveaways/${file}`);
const eventName = file.split(".")[0];
client.log(`(👌) Giveaway event loaded : ${eventName} !`, "event");
client.manager.on(eventName, event.bind());
delete require.cache[require.resolve(`./events/giveaways/${file}`)]
});
});
//Connect to mongoose database
mongoose.connect(config.mongoDB, { useNewUrlParser: true, useUnifiedTopology: true }).then(() => {
//If it connects log the following
client.log("Connected to the Mongodb database.", "done");
}).catch((err) => {
//If it doesn't connect log the following
client.log("Unable to connect to the Mongodb database. Error:" + err, "error");
});
// Login to bot
client.login(config.token);
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) => {
console.error(err);
});
/**
* Bot Coded by ! HaDi KouBeIssI | 🇱🇧#6256 | https://github.com/Hadi-Koubeissi/ManageGift
* Please mention Him ! HaDi KouBeIssI | 🇱🇧, when using this Code!
*/