Class Client

Main class used for receiving events and interacting with the Discord gateway.

Hierarchy

  • EventEmitter
    • Client

Properties

_restClient: SnowTransfer
options: Omit<IClientOptions, "snowtransferInstance"> & {
    endpoint?: string;
    token: string;
}
shardManager: ShardManager
token: string
version: string

Methods

  • Update the endpoint shard websockets will connect to.

    Parameters

    • gatewayUrl: string

      Base gateway wss url to update the cached endpoint to.

    Returns void

  • Type Parameters

    • E extends keyof ClientEvents

    Parameters

    • event: E
    • listener: ((...args: ClientEvents[E]) => any)
        • (...args: ClientEvents[E]): any
        • Parameters

          • Rest ...args: ClientEvents[E]

          Returns any

    Returns Client

  • Create one or more connections (depending on the selected amount of shards) to the Discord gateway.

    Returns

    This function returns a promise which is solely used for awaiting the getGateway() method's return value.

    Returns Promise<void>

  • Disconnect the bot gracefully, you will receive a 'disconnected' event once the ShardManager successfully closes all shard websocket connections.

    Returns void

  • Type Parameters

    • E extends keyof ClientEvents

    Parameters

    • event: E
    • Rest ...args: ClientEvents[E]

    Returns boolean

  • Returns (keyof ClientEvents)[]

  • Method to grab initial connection info from Discord. Should only be called automatically by the lib unless you are a large bot with a max_concurrency not equal to 1. If you are a large bot, you should call this method at a rate of your own discretion to update your max_concurrency cached value to have up to date bucket info.

    Returns

    The amount of shards the bot should spawn if set to auto.

    Returns Promise<number>

  • Get the gateway endpoint to connect to.

    Returns

    String url with the Gateway Endpoint to connect to.

    Returns Promise<string>

  • Get the GatewayData including recommended amount of shards and other helpful info.

    Returns

    Object with url and shards to use to connect to discord.

    Returns Promise<{}>

  • Parameters

    • event: keyof ClientEvents

    Returns number

  • Parameters

    • event: keyof ClientEvents

    Returns ((...args: any[]) => any)[]

  • Type Parameters

    • E extends keyof ClientEvents

    Parameters

    • event: E
    • listener: ((...args: ClientEvents[E]) => any)
        • (...args: ClientEvents[E]): any
        • Parameters

          • Rest ...args: ClientEvents[E]

          Returns any

    Returns Client

  • Type Parameters

    • E extends keyof ClientEvents

    Parameters

    • event: E
    • listener: ((...args: ClientEvents[E]) => any)
        • (...args: ClientEvents[E]): any
        • Parameters

          • Rest ...args: ClientEvents[E]

          Returns any

    Returns Client

  • Type Parameters

    • E extends keyof ClientEvents

    Parameters

    • event: E
    • listener: ((...args: ClientEvents[E]) => any)
        • (...args: ClientEvents[E]): any
        • Parameters

          • Rest ...args: ClientEvents[E]

          Returns any

    Returns Client

  • Type Parameters

    • E extends keyof ClientEvents

    Parameters

    • event: E
    • listener: ((...args: ClientEvents[E]) => any)
        • (...args: ClientEvents[E]): any
        • Parameters

          • Rest ...args: ClientEvents[E]

          Returns any

    Returns Client

  • Type Parameters

    • E extends keyof ClientEvents

    Parameters

    • event: E
    • listener: ((...args: ClientEvents[E]) => any)
        • (...args: ClientEvents[E]): any
        • Parameters

          • Rest ...args: ClientEvents[E]

          Returns any

    Returns Client

  • Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of all shards facilitated by this client's ShardManager.

    Returns

    Promise that's resolved once all shards have sent the websocket payload.

    Example

    // Connect to Discord and set status to do not disturb and game to "Memes are Dreams".
    const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
    const token = "token";
    const client = new CloudStorm.Client(token);
    client.connect();
    client.once("ready", () => {
    // Client is connected to Discord and is ready, so we can update the status.
    client.presenceUpdate({ status: "dnd", game: { name: "Memes are Dreams" } });
    });

    Parameters

    • data: GatewayPresenceUpdate

    Returns Promise<void>

  • Parameters

    • event: keyof ClientEvents

    Returns ((...args: any[]) => any)[]

  • Parameters

    • Optional event: keyof ClientEvents

    Returns Client

  • Type Parameters

    • E extends keyof ClientEvents

    Parameters

    • event: E
    • listener: ((...args: ClientEvents[E]) => any)
        • (...args: ClientEvents[E]): any
        • Parameters

          • Rest ...args: ClientEvents[E]

          Returns any

    Returns Client

  • Send an OP 8 REQUEST_GUILD_MEMBERS to Discord.

    Returns

    Promise that's resolved once the payload was send to Discord.

    Example

    // Connect to Discord and request guild members.
    const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
    const token = "token";
    const client = new CloudStorm.Client(token);
    client.connect();
    client.once("ready", () => {
    // Client is connected to Discord and is ready, so we can send the request guild members payload.
    // We will use shard 0 as the shard to send the payload.
    client.requestGuildMembers(0, { guild_id: "id" });
    });

    Parameters

    • shardId: number

      id of the shard that should send the payload.

    • data: GuildRequestMembersPayload & {
          limit?: number;
      }

      Request guild members data to send.

    Returns Promise<void>

  • Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of a single shard facilitated by this client's ShardManager.

    Returns

    Promise that's resolved once the shard has sent the websocket payload.

    Example

    // Connect to Discord and set status to do not disturb and game to "Im shard 0".
    const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
    const token = "token";
    const client = new CloudStorm.Client(token);
    client.connect();
    client.once("ready", () => {
    // Client is connected to Discord and is ready, so we can update the status of shard 0.
    client.shardPresenceUpdate(0, { status: "dnd", game: { name: "Im shard 0" } });
    });

    Parameters

    • shardId: number

      id of the shard that should update it's status.

    • data: GatewayPresenceUpdate

      Presence data to send.

    Returns Promise<void>

  • Send an OP 4 VOICE_STATE_UPDATE to Discord. this does not allow you to send audio with CloudStorm itself, it just provides the necessary data for another application to send audio data to Discord.

    Returns

    Promise that's resolved once the payload was sent to Discord.

    Example

    // Connect to Discord and join a voice channel
    const CloudStorm = require("cloudstorm"); // CloudStorm also supports import statements.
    const token = "token";
    const client = new CloudStorm.Client(token);
    client.connect();
    client.once("ready", () => {
    // Client is connected to Discord and is ready, so we can join a voice channel.
    // We will use shard 0 as the shard to send the payload.
    client.voiceStateUpdate(0, { guild_id: "id", channel_id: "id", self_mute: false, self_deaf: false });
    });

    Parameters

    • shardId: number

      id of the shard that should send the payload.

    • data: VoiceStateUpdatePayload & {
          self_deaf?: boolean;
          self_mute?: boolean;
      }

      Voice state update data to send.

    Returns Promise<void>

Constructors

  • Create a new Client to connect to the Discord gateway.

    Parameters

    • token: string

      Token received from creating a discord bot user, which will be used to connect to the gateway.

    • options: IClientOptions = {}

    Returns Client

Generated using TypeDoc