Options
All
  • Public
  • Public/Protected
  • All
Menu

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

Hierarchy

Index

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.

    • Optional options: IClientOptions

    Returns <internal>.Client

Properties

_restClient: any
_updateEndpoint: any

Update the endpoint shard websockets will connect to.

param gatewayUrl

Base gateway wss url to update the cached endpoint to.

options: Omit<IClientOptions, "snowtransferInstance"> & { endpoint?: string; token: string }
shardManager: ShardManager
token: string
version: string
default: typeof <internal>.Client
defaultMaxListeners: number

Methods

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

    Returns Promise<void>

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

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

    Returns void

  • fetchConnectInfo(): Promise<number>
  • 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 Promise<number>

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

  • Get the gateway endpoint to connect to.

    Returns Promise<string>

    String url with the Gateway Endpoint to connect to.

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

    Returns Promise<{ session_start_limit: <internal>.SessionStartLimit; shards: number; url: string }>

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

  • getMaxListeners(): number
  • listeners(event: keyof ClientEvents): ((...args: any[]) => any)[]
  • Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of all shards facilitated by this client's ShardManager.

    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

    Returns Promise<void>

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

  • rawListeners(event: keyof ClientEvents): ((...args: any[]) => any)[]
  • Send an OP 8 REQUEST_GUILD_MEMBERS 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

    Returns Promise<void>

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

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

    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

    Returns Promise<void>

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

  • 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.

    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: <internal>.VoiceStateUpdatePayload & { self_deaf?: boolean; self_mute?: boolean }

      Voice state update data to send.

    Returns Promise<void>

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

Generated using TypeDoc