-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathapp.js
53 lines (46 loc) · 1.64 KB
/
app.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
/* includes */
const Discord = require('discord.js');
const fs = require('fs');
const util = require('util');
const mongoose = require('mongoose');
/* defines & config */
const bot = new Discord.Client();
const readdir = util.promisify(fs.readdir);
bot.events = new Discord.Collection();
bot.commands = new Discord.Collection();
bot.data = require('./database/MongoDB.js');
bot.logger = require('./helpers/logger.js');
bot.tools = require('./helpers/tools.js');
bot.config = require('./config.json');
async function initialize() {
// load events
let events = fs.readdirSync('./events/').filter(file => file.endsWith('.js'));
for(let e of events) {
let eventFile = require('./events/' + e);
let eventName = e.split('.')[0];
bot.logger.event(eventName + ' loaded.');
bot.on(eventName, eventFile.bind(null, bot));
}
// load commands
let categories = await readdir('./commands/');
categories.forEach(c => {
let commands = fs.readdirSync('./commands/' + c + '/').filter(file => (file.endsWith('.js')));
for(const file of commands) {
let commandFile = require('./commands/' + c + '/' + file);
bot.commands.set(commandFile.name, commandFile);
}
bot.logger.cmd(c + ' - ' + commands.length + ' commands loaded.');
});
// init database
mongoose.connect(bot.config.mongoDB, {
useNewUrlParser: true,
useUnifiedTopology: true
}).then(() => {
bot.logger.log('MongoDB connected.');
}).catch((err) => {
bot.logger.error('MongoDB error - ' + err);
});
// login bot
bot.login(bot.config.token)
}
initialize();