Welcome to Status Sharding! This package is designed to provide an efficient and flexible solution for sharding Discord bots, allowing you to scale your bot across multiple processes or workers.
npm install status-sharding@discordjs/rest, @discordjs/ws, etc.).
bash
npm install status-sharding
pnpm add status-sharding
yarn add status-sharding
`
Usage
$3
This example demonstrates how to set up a cluster manager with Status Sharding. It works with any client implementation, providing automated shard distribution and cluster management.
`javascript
// import { ClusterManager } from 'status-sharding';
const { ClusterManager } = require("status-sharding");
const manager = new ClusterManager("./path-to-client.js", {
mode: "worker", // or process
token: "very-secret-token", // optional, for auto-calculation leave empty
totalShards: 1, // leave empty for auto calculation
totalClusters: 1, // shards are distributed over clusters
shardsPerClusters: 1,
});
manager.on("clusterReady", (cluster) => {
console.log(Cluster ${cluster.id} is ready.);
});
manager.on("ready", () => console.log("All clusters are ready."));
manager.spawn();
`
> Note: Replace './path-to-client.js' with your actual client file path, and 'very-secret-token' with your Discord bot token.
---
$3
Here’s a minimal example of using Status Sharding with discord.js. It leverages the ShardingClient class to handle shards automatically.
`javascript
// import { ShardingClient } from 'status-sharding';
// import { GatewayIntentBits, Events } from 'discord.js';
const { ShardingClient } = require("status-sharding");
const { GatewayIntentBits, Events } = require("discord.js");
const client = new ShardingClient({
intents: [GatewayIntentBits.Guilds, GatewayIntentBits.GuildMembers],
});
client.once(Events.ClientReady, () => {
console.log("Ready!");
});
client.login("very-secret-token");
`
This setup ensures your bot scales efficiently without requiring manual shard management.
---
$3
For developers using @discordjs/core, Status Sharding provides ShardingCoreClient to integrate seamlessly with the core library and REST API.
`javascript
// import { ShardingCoreClient } from 'status-sharding/core';
// import { GatewayDispatchEvents, GatewayIntentBits } from '@discordjs/core';
const { ShardingCoreClient } = require("status-sharding/core");
const { GatewayDispatchEvents, GatewayIntentBits } = require("@discordjs/core");
const client = new ShardingCoreClient({
token: "very-secret-token",
gateway: {
intents: GatewayIntentBits.Guilds | GatewayIntentBits.GuildMembers,
},
rest: {
version: "10",
},
});
client.once(GatewayDispatchEvents.Ready, () => {
console.log("Ready!");
});
client.gateway.connect();
`
This example demonstrates full integration with @discordjs/core`, including gateway connection and event handling, while still benefiting from automated shard and cluster management.