oceanic.js
Version:
A NodeJS library for interfacing with Discord.
90 lines (89 loc) • 3.42 kB
TypeScript
/// <reference types="node" />
/** @module Shard */
import type ShardManager from "./ShardManager";
import type Client from "../Client";
import TypedEmitter from "../util/TypedEmitter";
import Bucket from "../rest/Bucket";
import { GatewayOPCodes } from "../Constants";
import type { UpdatePresenceOptions, RequestGuildMembersOptions, UpdateVoiceStateOptions, SendStatuses, BotActivity, ShardStatus, RequestSoundboardSoundsOptions } from "../types/gateway";
import type Member from "../structures/Member";
import type { ShardEvents } from "../types/events";
import type Soundboard from "../structures/Soundboard";
import WebSocket from "ws";
import { inspect } from "node:util";
/** Represents a gateway connection to Discord. See {@link ShardEvents | Shard Events} for a list of events. */
export default class Shard extends TypedEmitter<ShardEvents> {
private _compressor;
private _connectTimeout;
private _getAllUsersCount;
private _getAllUsersQueue;
private _guildCreateTimeout;
private _heartbeatInterval;
private _requestMembersPromise;
private _requestSoundboardSoundsPromise;
client: Client;
connectAttempts: number;
connecting: boolean;
globalBucket: Bucket;
id: number;
lastHeartbeatAck: boolean;
lastHeartbeatReceived: number;
lastHeartbeatSent: number;
latency: number;
manager: ShardManager;
preReady: boolean;
presence: Required<UpdatePresenceOptions>;
presenceUpdateBucket: Bucket;
ready: boolean;
reconnectInterval: number;
resumeURL: string | null;
sequence: number;
sessionID: string | null;
status: ShardStatus;
ws: WebSocket | null;
constructor(id: number, manager: ShardManager);
private _ready;
private _resume;
private checkReady;
private createGuild;
private initialize;
private onPacket;
private onWSClose;
private onWSError;
private onWSMessage;
private onWSOpen;
private restartGuildCreateTimeout;
private sendPresenceUpdate;
private get _token();
/** Connect this shard. */
connect(): Promise<void>;
disconnect(reconnect?: boolean, error?: Error): void;
/**
* Edit this shard's status.
* @param status The status.
* @param activities An array of activities.
*/
editStatus(status: SendStatuses, activities?: Array<BotActivity>): Promise<void>;
hardReset(): void;
heartbeat(requested?: boolean): void;
identify(): void;
[inspect.custom](): this;
/**
* Request the members of a guild.
* @param guildID The ID of the guild to request the members of.
* @param options The options for requesting the members.
*/
requestGuildMembers(guildID: string, options?: RequestGuildMembersOptions): Promise<Array<Member>>;
requestSoundboardSounds(guildID: string, options?: RequestSoundboardSoundsOptions): Promise<Array<Soundboard>>;
reset(): void;
resume(): void;
send(op: GatewayOPCodes, data: unknown, priority?: boolean): void;
toString(): string;
/**
* Update the voice state of this shard.
* @param guildID The ID of the guild to update the voice state of.
* @param channelID The ID of the voice channel to join. Null to disconnect.
* @param options The options for updating the voice state.
*/
updateVoiceState(guildID: string, channelID: string | null, options?: UpdateVoiceStateOptions): void;
}