Skip to content

@lunibee/sharding

The @lunibee/sharding package helps large Discord bots split Gateway connections across multiple shards and communicate between them.

Terminal window
bun add @lunibee/sharding @lunibee/types
import { ShardManager } from "@lunibee/sharding";
import { IntentBits } from "@lunibee/types";
const manager = new ShardManager({
token: process.env.DISCORD_TOKEN!,
intents: IntentBits.guilds | IntentBits.guildMessages,
shardCount: "auto",
});
await manager.connect();

Use automatic shard counts unless you have a reason to control the count yourself.

Use ShardBus when shards need to send application-level messages to each other.

import { ShardBus } from "@lunibee/sharding";
const bus = new ShardBus(0, "lunibee-bot");
bus.on("RELOAD_CONFIG", (message) => {
console.log("Reload requested by shard", message.source);
});
bus.broadcast("RELOAD_CONFIG", { reason: "admin_request" });

A small bot normally starts with a single Client. Sharding becomes useful when the bot grows enough that Discord requires multiple Gateway sessions or when you want to distribute Gateway work across processes.