Enterprise Bun-native sharding manager for Discord bots, featuring Redis heartbeats, rolling restarts, and integrated monitoring.
npm install buncord-hybrid-sharding
buncord-hybrid-sharding is a ground-up refactor of the hybrid sharding concept, optimized specifically for the Bun runtime. It eliminates all Node.js dependencies, leveraging Bun.spawn and native Bun IPC for ultra-fast, low-overhead clustering.
Bun.spawn and native IPC for maximum performance.
ReClusterManager for updating your bot with zero service interruption.
Bun.serve to track cluster health and trigger administrative actions.
bash
bun add buncord-hybrid-sharding
`
🛠️ Quick Start
$3
`js
import { ClusterManager, ReClusterManager, HeartbeatManager, DashboardServer } from 'buncord-hybrid-sharding';
const manager = new ClusterManager(./bot.js, {
totalShards: 'auto',
shardsPerClusters: 2,
mode: 'process', // Native Bun processes
token: 'YOUR_BOT_TOKEN',
});
// Extend with Enterprise features
manager.extend(
new ReClusterManager(),
new HeartbeatManager({
redis: { host: 'localhost', port: 6379 },
interval: 10000,
}),
new DashboardServer({ port: 3001 })
);
manager.on('clusterCreate', (cluster) => console.log(🚀 Launched Cluster ${cluster.id}));
manager.spawn();
`
$3
`js
import { ClusterClient, getInfo } from 'buncord-hybrid-sharding';
import { Client, GatewayIntentBits } from 'discord.js';
const client = new Client({
shards: getInfo().SHARD_LIST,
shardCount: getInfo().TOTAL_SHARDS,
intents: [GatewayIntentBits.Guilds],
});
client.cluster = new ClusterClient(client);
client.on('ready', () => {
client.cluster.triggerReady();
console.log(✅ Cluster ${client.cluster.id} is ready!);
});
client.login('YOUR_BOT_TOKEN');
`
---
📈 Monitoring API
The built-in DashboardServer provides a JSON API for monitoring and management:
- GET /stats: Unified metrics across all clusters.
- POST /restart: Trigger a rolling restart.
- POST /maintenance: Toggle maintenance mode.
---
📝 License
This project is licensed under the MIT License. See the LICENSE file for details.
Portions of this code are based on discord.js and discord-hybrid-sharding`, copyright of their respective authors.