-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathindex.js
More file actions
57 lines (44 loc) · 1.92 KB
/
index.js
File metadata and controls
57 lines (44 loc) · 1.92 KB
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
const { ShardingManager } = require('discord.js');
const token = process.env.DISCORD_TOKEN;
const ConsoleHandler = require('./src/util/ConsoleHandler');
const path = require('path');
const manager = new ShardingManager(path.join(__dirname, 'app.js'), { token: token, totalShards: 'auto', respawn: true });
manager.on('shardCreate', function(shard) {
ConsoleHandler.log(shard, `Shard ${shard.id + 1}/${parseInt(manager.totalShards)} initiating..`);
shard.on('death', function() {
ConsoleHandler.error(shard, `Shard ${shard.id} died..`);
});
shard.on('disconnect', function() {
ConsoleHandler.debug(shard, `Shard ${shard.id} disconnected..`);
});
shard.on('reconnecting', function() {
ConsoleHandler.debug(shard, `Shard ${shard.id} reconnecting..`);
});
shard.on('close', function(code) {
ConsoleHandler.error(shard, `Shard ${shard.id} closed all stdio with code ${code}`);
});
shard.on('exit', function(code) {
ConsoleHandler.error(shard, `Shard ${shard.id} exited with code ${code}`);
});
shard.on('message', function(data) {
if (data instanceof Object && typeof data == "object") {
if (!data.message || !data.type) ConsoleHandler.log(shard, data.message||data);
switch(data.type) {
case 'debug':
ConsoleHandler.debug(shard, data.message);
break;
case 'warn':
ConsoleHandler.warn(shard, data.message);
break;
case 'error':
ConsoleHandler.error(shard, data.message);
break;
default:
ConsoleHandler.log(shard, data.message);
}
} else {
ConsoleHandler.log(shard, data);
}
});
});
manager.spawn(manager.totalShards).catch(console.error);