sharding.js
v1.0.2
Published
A high-performance, cross-machine sharding manager for Discord bots using Redis.
Maintainers
Readme
Sharding.js
🚀 A high-performance, cross-machine sharding manager for Discord bots.
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.
📌 Features
- 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
📦 Installation
npm install sharding.js🛠 Usage
Initialize the Sharding Manager
import { ShardingManager } from "sharding.js";
const manager = new ShardingManager("YOUR_DISCORD_TOKEN", 10);
manager.spawnShards(0, 9);Creating a Custom Shard
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();Cross-Shard Communication
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);
});⚙️ Configuration
Ensure Redis is installed and running before using sharding.js.
Start Redis locally with:
redis-serverFor multiple machines, configure all instances to use the same Redis server.
📜 License
This project is licensed under the MIT License - see the LICENSE file for details.
