Step by Step

Status Sharding allows you to efficiently shard your Discord bot across multiple processes or workers. Whether you’re using discord.js or @discordjs/core, this package provides a simple, scalable way

index.js
// 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', // if you want auto-calculation do not provide stuff below
    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();

Make sure to replace 'path-to-client.js' with the actual path to your client file. Also, replace 'very-secret-token' with your actual Discord bot token.

Usage with discord.js

Here’s a minimal example of using Status Sharding with discord.js. It leverages the ShardingClient class to handle shards automatically.

client.js
// import { ShardingClient } from 'status-sharding';
// import { GatewayIntentBits } from 'discord.js';
const { ShardingClient } = require('status-sharding');
const { GatewayIntentBits } = require('discord.js');

const client = new ShardingClient({
    intents: [GatewayIntentsBits.Guilds]
});

client.login('very secret token');

Usage with @discordjs/core

For developers using @discordjs/core, Status Sharding provides ShardingCoreClient to integrate seamlessly with the core library and REST API.

// import { ShardingCoreClient } from 'status-sharding';
// import { GatewayDispatchEvents, GatewayIntentBits } from '@discordjs/core';
const { ShardingCoreClient } = require('status-sharding');
const { GatewayDispatchEvents, GatewayIntentBits } = require('@discordjs/core');

const client = new ShardingCoreClient({
    token: 'very-secret-token',
    gateway: {
        intents: GatewayIntentBits.Guilds | GatewayIntentBits.GuildPresences | GatewayIntentBits.GuildMembers,
    },
    rest: {
        version: '10',
    },
});

client.once(GatewayDispatchEvents.Ready, () => {
    console.log('Ready!');
});

client.gateway.connect();

Last updated

Was this helpful?