-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
72 lines (57 loc) · 2.12 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
66
67
68
69
70
71
72
/*jshint esversion: 6 */
const Discord = require('discord.js');
const dotenv = require('dotenv').load();
const Enmap = require("enmap");
const fs = require("fs");
const checkStatus = require('./modules/check-status');
const client = new Discord.Client();
const botConfig = {
"prefix": process.env.BOT_PREFIX,
"token": process.env.BOT_TOKEN,
"status-channel": process.env.STATUS_CHANNEL,
"log-channel": process.env.LOG_CHANNEL,
"pingURL": process.env.PING_URL,
"checkName": process.env.CHECK_NAME,
"checkTime": process.env.CHECK_TIME * 1000
};
client.config = botConfig;
const logger = require("./modules/logger");
client.logger = logger;
client.on('error', console.error);
let env = 'production (environment not specified by user)';
if (process.env.ENV !== null && process.env.ENV.trim() !== ''){
env = process.env.ENV;
}
client.on('ready', () => {
logger.log(`${client.user.tag}, ready to serve ${client.users.size} users in ${client.guilds.size} servers, while running in ${env}. My prefix is ${botConfig.prefix}`, "ready");
setInterval(() => {
checkStatus(client);
}, botConfig.checkTime);
});
fs.readdir("./events/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
const event = require(`./events/${file}`);
let eventName = file.split(".")[0];
client.on(eventName, event.bind(null, client));
});
});
client.commands = new Enmap();
fs.readdir("./commands/", (err, files) => {
if (err) return console.error(err);
files.forEach(file => {
if (!file.endsWith(".js")) return;
let props = require(`./commands/${file}`);
let commandName = file.split(".")[0];
console.log(`Attempting to load command ${commandName}`);
client.commands.set(commandName, props);
});
});
process.on("uncaughtException", (err) => {
const errorMsg = err.stack.replace(new RegExp(`${__dirname}/`, "g"), "./");
client.logger.error(`Uncaught Exception: ${errorMsg}`);
});
process.on("unhandledRejection", err => {
client.logger.error(`Unhandled rejection: ${err}`);
});
client.login(botConfig.token);