Sharding.js is an advanced sharding manager designed for Discord bots, enabling seamless communication between multiple shards across different machines using Redis for inter-process communication.
- Cross-machine sharding (Supports multiple servers/IPs)
- Redis-based IPC for efficient inter-shard communication
- Auto-reconnect handling to prevent downtime
- Lightweight and dependency-free (No Discord.js required)
- Fully TypeScript-supported with type definitions
npm install sharding.js
import { ShardingManager } from "sharding.js";
const manager = new ShardingManager("YOUR_DISCORD_TOKEN", 10);
manager.spawnShards(0, 9);
import { Shard } from "sharding.js";
const shard = new Shard(0, "YOUR_DISCORD_TOKEN", 10);
shard.on("event", (event, data) => {
console.log(`Received event: ${event}`, data);
});
shard.connect();
Shards communicate using Redis. You can listen for events from other shards:
shard.on("cross-shard-event", (event, data) => {
console.log(`Received cross-shard event: ${event}`, data);
});
Ensure Redis is installed and running before using sharding.js
.
Start Redis locally with:
redis-server
For multiple machines, configure all instances to use the same Redis server.
This project is licensed under the MIT License - see the LICENSE file for details.