-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
52 lines (41 loc) · 1.94 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
//import libraries (only required one)
const Discord = require ("discord.js");
const client = new Discord.Client();
const fs = require('fs');
const log = require('./elainaRebuild-utils/log.js')
const mainConfig = require('./elainaRebuild-config/config.json');
const DatabaseConnection = require('./elainaRebuild-data/databaseconnection.js')
require('dotenv').config({ path: 'elainaRebuild-config/.env' })
client.commands = new Discord.Collection();
//import event handlers
fs.readdir('./elainaRebuild-event/', (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
let EventHandler = require(`./elainaRebuild-event/${file}`);
log.toConsole(`${file} event loaded`)
const event = EventHandler.name || file.split('.')[0]; // Get the exact name of the event from the eventFunction variable. If it's not given, the code just uses the name of the file as name of the event
const emitter = (typeof EventHandler.emitter === 'string' ? client[EventHandler.emitter] : EventHandler.emitter) || client;
// Try catch block to throw an error if the code in try{} doesn't work
try {
emitter['on'](event, (...args) => EventHandler.execute(client, ...args)); // Run the event using the above defined emitter (client)
} catch (error) {
log.errConsole(error.stack); // If there is an error, console log the error stack message
}
})
client.login(process.env.DISCORD_TOKEN);
})
//import command handlers
fs.readdir('./elainaRebuild-cmd/', (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
let commandHandler = require(`./elainaRebuild-cmd/${file}`);
if (commandHandler.isEnable !== true) {
log.toConsole(`(x) ${file} command is disable`)
return
}
client.commands.set(commandHandler.name, commandHandler)
log.toConsole(`${file} command loaded`)
})
})
//connection to database
DatabaseConnection.initConnection();