The AutoResharderManager automatically re-shards the bot when the number of guilds per shard exceeds a configured limit.
Setup Steps:
- Extend the
ClusterManager with AutoResharderManager. - On every client, instantiate an
AutoResharderClusterClient to send guild count data to the manager.
Configuration Options for AutoResharderManager:
debug: Boolean to enable debug info.ShardsPerCluster: Number of shards per cluster (or 'useManagerOption').MinGuildsPerShard: Minimum guilds per shard (or auto).MaxGuildsPerShard: Maximum guilds per shard before triggering a re-shard.restartOptions: Configuration for the ClusterManager (includes restartMode, delay, and timeout).
Configuration for AutoResharderClusterClient:
sendDataIntervalMS: Interval for sending data (default 60e3).sendDataFunction: A function that returns the clusterId and shardData (an array of { shardId, guildCount }).
// Manager side
manager.extend(new AutoResharderManager(this.cluster, {
debug: true,
ShardsPerCluster: 'useManagerOption',
MinGuildsPerShard: 1400,
MaxGuildsPerShard: 2400,
}));
// Client side
client.cluster = new ClusterClient(client);
new AutoResharderClusterClient(client.cluster, {
sendDataIntervalMS: 60e3,
sendDataFunction: (cluster) => {
return {
clusterId: cluster.id,
shardData: cluster.client.guildsche.filter(g => g.shardId === shardId).map(shardId => ({
shardId,
guildCount: cluster.client.guildsche.filter(g => g.shardId === shardId).size
}))
}
}
});