status-sharding
Version:
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.
41 lines (40 loc) • 1.51 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.ShardingCoreClient = void 0;
const core_1 = require("@discordjs/core");
const ws_1 = require("@discordjs/ws");
const rest_1 = require("@discordjs/rest");
const clusterClient_1 = require("./clusterClient");
const utils_1 = require("../other/utils");
/** Modified DiscordClient with bunch of new methods. */
class ShardingCoreClient extends core_1.Client {
/** Cluster associated with this client. */
cluster;
/* The WebSocket manager of this client. */
gateway;
/** The REST manager of this client. */
rest;
/* Shards Ready Count. */
shardsReady = 0;
/** Creates an instance of ShardingCoreClient. */
constructor(options) {
const info = (0, utils_1.getInfo)();
const rest = new rest_1.REST(options.rest).setToken(options.token);
const gateway = new ws_1.WebSocketManager({
token: options.token, ...options.gateway,
shardCount: info.TotalShards,
shardIds: info.ShardList,
rest,
});
super({ rest, gateway });
this.rest = rest;
this.gateway = gateway;
this.cluster = new clusterClient_1.ClusterClient(this);
this.on(core_1.GatewayDispatchEvents.Ready, () => {
this.shardsReady++;
if (this.shardsReady === info.ShardList.length)
this.cluster.triggerReady();
});
}
}
exports.ShardingCoreClient = ShardingCoreClient;