-
Notifications
You must be signed in to change notification settings - Fork 23
/
index.js
48 lines (37 loc) · 1.09 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
require('dotenv').config();
const discord = require('discord.js');
const fs = require('fs');
const client = new discord.Client();
client.on('ready', () => {
console.log(`Logged in as ${client.user.tag}!`);
});
const modules = fs.readdirSync(`${__dirname}/modules`).map(module => {
console.log(`Loading module: ${module}`);
return require(`./modules/${module}`);
});
modules.forEach(module => module(client));
console.log(`Loaded ${modules.length} modules`);
client
.login(process.env.DISCORD_BOT_TOKEN)
.then(() => console.log('✅ Ready'))
.catch(console.error);
registerShutdownHooks(client);
function registerShutdownHooks(client) {
const signals = {
SIGHUP: 1,
SIGINT: 2,
SIGTERM: 15,
};
function shutdown(signal, value) {
console.log('Shutting down...');
client.destroy();
console.log(`Client stopped by ${signal} with value ${value}`);
process.exit(128 + value);
}
Object.keys(signals).forEach(signal => {
process.on(signal, () => {
console.log(`Process received a ${signal} signal`);
shutdown(signal, signals[signal]);
});
});
}