-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathindex.js
65 lines (50 loc) · 1.66 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
/**
* Tanki Bot
*
* Main index file.
*
* @author gbfactory
* @since 12.07.2017
*/
const Discord = require('discord.js');
const mysql = require("mysql");
const fs = require('fs');
const config = require('./config.json');
const functions = require('./utils/functions');
// Enviroment
let env = config['dev'] ? 'development' : 'production';
console.log(`[Tanki Bot] Starting in ${env}`);
// Database Connection
var con = mysql.createConnection({
host: config[env]['database']['host'],
user: config[env]['database']['user'],
password: config[env]['database']['password'],
database: config[env]['database']['database']
});
con.connect(err => {
if (err) throw err;
console.log("[Tanki Bot] Connected to the database!");
})
// New discord client
const client = new Discord.Client();
// Commands Collection
client.commands = new Discord.Collection();
const commandsDirs = fs.readdirSync('./commands');
for (const dir of commandsDirs) {
const commandFiles = fs.readdirSync(`./commands/${dir}`).filter(file => file.endsWith('.js'));
for (const file of commandFiles) {
const command = require(`./commands/${dir}/${file}`);
client.commands.set(command.name, command);
}
}
// Cooldowns
const cooldowns = new Discord.Collection();
// Event Handler
const eventsFiles = fs.readdirSync('./events').filter(file => file.endsWith('.js'));
for (const file of eventsFiles) {
const event = require(`./events/${file}`);
const name = file.split('.')[0];
client.on(name, event.bind(null, client, con, cooldowns, functions));
}
// Token
client.login(config[env]['token']);