-
Notifications
You must be signed in to change notification settings - Fork 0
/
launch.js
55 lines (44 loc) · 1.3 KB
/
launch.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
require("dotenv").config();
const { ClusterManager, HeartbeatManager, ReClusterManager } = require("discord-hybrid-sharding");
const { Logger } = require("term-logger");
const config = require("./config");
const manager = new ClusterManager(`${__dirname}/base/bot.js`, {
totalShards: 1,
shardsPerClusters: 5,
mode: "process",
respawn: true,
restarts: {
max: "Infinity",
interval: 60000 * 60,
},
spawnOptions: {
timeout: 30000,
},
token: process.env.CLIENT_AUTH_TOKEN,
});
console.clear();
Logger.pending(`Starting cluster manager on ${manager.mode} mode...`);
manager.on("clusterCreate", (cluster) => {
Logger.cluster(`Cluster ${cluster.id} successfully launched`);
cluster.on("death", (cc, t) => {
Logger.error(`Cluster DIED`);
console.log(`ID: ${cc.id}`);
console.log(`Exit Code: ${t.exitCode}`);
console.log(`Killed: ${t.killed}`);
console.log(`Args: ${t.spawnargs}`);
});
cluster.on("error", (e) => {
Logger.error(`Cluster ERROR`);
console.log(e.name);
console.log(e.message);
console.log(e.stack);
});
});
if (config.status === "PROD") {
manager.on("debug", Logger.debug);
}
manager.extend(
new HeartbeatManager({ interval: 5000, maxMissedHeartbeats: 10 }),
new ReClusterManager({ restartMode: "rolling" })
);
manager.spawn({ timeout: -1 }).catch((e) => Logger.error(e));