-
Notifications
You must be signed in to change notification settings - Fork 89
Expand file tree
/
Copy pathindex.js
More file actions
executable file
·36 lines (30 loc) · 1.15 KB
/
index.js
File metadata and controls
executable file
·36 lines (30 loc) · 1.15 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
'use strict';
import 'dotenv/config';
import { AutoResharderManager, ClusterManager, HeartbeatManager, ReClusterManager } from 'discord-hybrid-sharding';
import { beaver } from './functions/consoleLogging.js';
// The number of shards to use per cluster
// Higher values save memory but put more pressure on the thread
const shardsPerClusters = parseInt(process.env.SPC || 4);
// Create the cluster manager
// Spawns instances of shards specified in bot.js
let manager = new ClusterManager('./bot.js', {
shardsPerClusters: shardsPerClusters,
token: process.env.TOKEN,
mode: 'process',
});
manager.extend(new ReClusterManager());
manager.extend(new AutoResharderManager());
manager.extend(new HeartbeatManager());
manager.on('clusterCreate', (cluster) => beaver.log('sharding', `Created cluster ${cluster.id}`));
// Spawn the clusters and set an interval to check for recommended shard count every 24 hours
// Timeout is set to -1 since each shard takes a while to initialize
async function spawnShards() {
beaver.log('sharding', `Starting bot!`);
await manager.spawn();
}
// Start the bot
try {
spawnShards();
} catch (error) {
beaver.log('sharding', error);
}