-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
41 lines (36 loc) · 1.3 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
require('dotenv').config();
const fs = require('fs');
const Discord = require('discord.js');
const { logger } = require('./utils/logger');
const { token } = JSON.parse(process.env.CONFIG);
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.MESSAGE_CONTENT,
],
});
client.login(token);
client.commands = new Discord.Collection();
client.events = new Discord.Collection();
client.configs = new Discord.Collection();
const handleFiles = fs.readdirSync('./handlers').filter((file) => file.endsWith('.js'));
handleFiles.forEach((file) => {
require(`./handlers/${file}`)(client);
});
function exitHandler(options, exitCode) {
logger.error('Process Exiting');
if (exitCode || exitCode === 0) console.log(exitCode);
if (options.exit) process.exit();
}
process
.on('unhandledRejection', (err, p) => {
logger.error(`Error: ${err.message} | ${err?.stack} Unhandled Rejection at Promise: ${p}`);
})
.on('uncaughtException', (err) => {
logger.error(`UncaughtException: ${err.message} | ${err?.stack}`);
process.exit(1);
})
.on('SIGINT', exitHandler.bind(null, { exit: true }))
.on('SIGTERM', exitHandler.bind(null, { exit: true }));
module.exports = { client };