-
Notifications
You must be signed in to change notification settings - Fork 1
/
index.js
50 lines (40 loc) · 1.58 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
require('dotenv').config();
const Discord = require("discord.js");
const client = new Discord.Client();
const alive = require("./alive.js")
const config = require("./config.json"),
fs = require("fs"),
util = require("util"),
readdir = util.promisify(fs.readdir),
mongoose = require("mongoose");
client.logger = require("./modules/Logger.js");
client.errors = require("./modules/Embeds.js");
client.tools = require("./modules/Tools.js");
client.data = require("./modules/MongoDB.js");
client.events = new Discord.Collection();
client.commands = new Discord.Collection();
client.categories = [];
async function init(){
const eventFiles = fs.readdirSync('./events/').filter(file => file.endsWith('.js'));
for (const file of eventFiles) {
const event = require(`./events/${file}`);
const eventName = file.split(".")[0];
client.logger.event(`Loading Event - ${eventName}`);
client.on(eventName, event.bind(null, client));
}
let folders = await readdir("./commands/");
folders.forEach(direct =>{
const commandFiles = fs.readdirSync('./commands/' + direct + "/").filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${direct}/${file}`);
client.commands.set(command.name, command);
}
})
mongoose.connect(process.env.mongoDB, { useNewUrlParser: true, useUnifiedTopology: true }).then(() => {
client.logger.log("Connected to the Mongodb database.", "log");
}).catch((err) => {
client.logger.log("Unable to connect to the Mongodb database. Error:"+err, "error");
});
}
init();
client.login(process.env.TOKEN);