-
-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathCluster.js
More file actions
37 lines (35 loc) · 1.25 KB
/
Cluster.js
File metadata and controls
37 lines (35 loc) · 1.25 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
'use strict';
const Cluster = require('discord-hybrid-sharding');
const appsettings = require('./appsettings.json');
const logging = require('./Utils/logging');
const manager = new Cluster.Manager(`${__dirname}/bot.js`, {
totalShards: 'auto',
mode: 'process', // you can also choose "worker"
shardsPerClusters: 2,
token: appsettings.token,
respawn: true,
spawnOptions: {
delay: 20000,
timeout: -1
}
});
manager.on('clusterCreate', async (cluster) => {
logging.logger.info(`Launched Cluster ${cluster.id}`);
cluster.on('spawn', spawnedCluster => {
logging.logger.info(`Spawned Cluster with PID ${spawnedCluster?.pid}`);
});
cluster.on('ready', async () => {
logging.logger.info(`Cluster ${cluster?.id} is ready`);
await cluster.send({ type: 'shardId', data: { shardId: cluster?.id } });
});
cluster.on('disconnect', (disconnectedCluster) => {
logging.logger.info(`Cluster ${disconnectedCluster?.id} disconnected`);
});
cluster.on('error', err => {
logging.logger.error(`Error in ${cluster.id}: ${err}`);
});
cluster.on('death', () => {
logging.logger.error(`RIP Bozo! Cluster ${cluster.id}`);
});
});
manager.spawn({ delay: 20000, timeout: -1 });