-
Notifications
You must be signed in to change notification settings - Fork 16
/
main.js
61 lines (51 loc) · 1.79 KB
/
main.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
const Discord = require('discord.js');
const fs = require('fs');
const DBL = require("dblapi.js");
const Sqlite = require('./db/sqlite');
const Timeout = require('./extensions/timeout');
const utils = require('./utils');
const client = new Discord.Client({
// According to https://github.com/discordjs/discord.js/blob/stable/src/util/Constants.js#L19
// this should be set to true to get always the right ammount of members
// per guild. - zekro
fetchAllMembers: true
});
const debugMode = process.argv.includes('debug');
try {
client.config = require('./config.json');
if (debugMode)
client.config = client.config.debug;
} catch (err) {
console.error('[ FATAL ] Failed parsing config.json: ', err);
process.exit(1);
}
client.setInterval(function() {
utils.updateNicknameChanges(client);
}, 30 * 60000);
client.embeds = require('./embeds.js');
client.dbl = new DBL(client.config.dblToken);
client.db = new Sqlite(client.config.dbFile);
client.timeout = new Timeout()
.register('cmdupdate', 30 * 1000, 1);
// Getting commands from ./commands/
client.commands = new Map();
let commandFiles = fs.readdirSync('./commands');
commandFiles.forEach(file => {
if (file.endsWith('.js')) {
console.log("[ LOADING ] [ COMMAND ] " + file);
client.commands.set(file.split('.')[0], require(`./commands/${file}`));
}
});
// Getting events from ./events/
let eventFiles = fs.readdirSync('./events');
eventFiles.forEach(file => {
if (file.endsWith('.js')) {
console.log("[ LOADING ] [ EVENT ] " + file);
let eventFunction = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, (...args) => {
eventFunction.run(...args, client);
});
}
});
client.login(client.config.token);