import { EventEmitter } from "node:events"; import ShardManager = require("./ShardManager"); import type { APIGatewayBotInfo } from "discord-api-types/v10"; import type { ClientEvents, IClientOptions, IShardResumeData } from "./Types"; /** * Main class used for receiving events and interacting with the Discord gateway. * @since 0.1.4 */ declare class Client extends EventEmitter { /** The Discord auth token to connect with. */ token: string; /** User specific options filled in with defaults if not specified. */ options: Omit & { token: string; endpoint?: string; }; /** The manager of all of the shards used to connect to Discord. */ shardManager: ShardManager; /** The version string of CloudStorm. */ version: string; /** The SnowTransfer instance to use to make some requests to get connect info. */ private readonly _restClient; /** * Create a new Client to connect to the Discord gateway. * @param token Token received from creating a discord bot user, which will be used to connect to the gateway. * @param options Baseline options to use. Will be filled with defaults if not specified. */ constructor(token: string, options?: IClientOptions); /** * Create one or more connections (depending on the selected amount of shards) to the Discord gateway. * @since 0.1.4 * @returns This function returns a promise which is solely used for awaiting the getGateway() method's return value. */ connect(): Promise; /** * 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. * @since 0.5.0 * @returns The amount of shards the bot should spawn if set to auto. */ fetchConnectInfo(): Promise; /** * Get the gateway endpoint to connect to. * @since 0.1.4 * @returns String url with the Gateway Endpoint to connect to. */ getGateway(): Promise; /** * Get the GatewayData including recommended amount of shards and other helpful info. * @since 0.1.4 * @returns Object with url and shards to use to connect to discord. */ getGatewayBot(): Promise; /** * Disconnect the bot gracefully, * you will receive a 'disconnected' event once the ShardManager successfully closes all shard websocket connections. * @since 0.1.4 * @param resumable Whether to close with a code that keeps the sessions alive on Discord's end, so another * process can resume them via getResumeData() and the resumeData client option. The default close destroys them. */ disconnect(resumable?: boolean): void; /** * Collect everything needed to resume all shards' sessions after a process restart, keyed by shard id. * Resuming doesn't count against the daily identify limit and replays the events missed while disconnected. * * Take the snapshot AFTER disconnecting with client.disconnect(true) - a regular disconnect destroys the sessions, * and a snapshot taken while still connected can go stale as more events arrive if they get processed. * Shards whose sessions Discord no longer accepts fall back to identifying automatically. * The returned object is JSON-serializable as-is. * @since 0.19.0 * * @example * // Before shutting down: * client.once("disconnected", () => { * fs.writeFileSync("./resume.json", JSON.stringify(client.getResumeData())); * process.exit(0); * }); * client.disconnect(true); * * // After restarting: * const client = new CloudStorm.Client(token, { resumeData: JSON.parse(fs.readFileSync("./resume.json", "utf8")) }); * client.connect(); */ getResumeData(): Record; /** * Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of all shards facilitated by this client's ShardManager. * @since 0.3.0 * @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 activity 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", activities: [{ name: "Memes are Dreams", type: 0 }] }); * }); */ presenceUpdate(data: Parameters["0"]): Promise; /** * Send an OP 3 PRESENCE_UPDATE to Discord, which updates the status of a single shard facilitated by this client's ShardManager. * @since 0.11.0 * @param shardId id of the shard that should update it's status. * @param data Presence data to send. * @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 activity to "I'm 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", activities: [{ name: "I'm shard 0", type: 0 }] }); * }); */ shardPresenceUpdate(shardId: number, data: Parameters["1"]): Promise; /** * 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. * @since 0.1.4 * @param shardId id of the shard that should send the payload. * @param data Voice state update data to send. * @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 }); * }); */ voiceStateUpdate(shardId: number, data: Parameters["1"]): Promise; /** * Send an OP 8 REQUEST_GUILD_MEMBERS to Discord. * @since 0.1.4 * @param shardId id of the shard that should send the payload. * @param data Request guild members data to send. * @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" }); * }); */ requestGuildMembers(shardId: number, data: Parameters["1"]): Promise; /** * Send an OP 31 REQUEST_SOUNDBOARD_SOUNDS to Discord. * @param shardId id of the shard that should send the payload. * @param guilds Guild ids to request soundboard sounds from. * @returns Promise that's resolved once the payload was send to Discord. * * @example * // Connect to Discord and request soundboard sounds. * 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 soundboard sounds payload. * // We will use shard 0 as the shard to send the payload. * client.requestSoundboardSounds(0, ["id"]); * }); */ requestSoundboardSounds(shardId: number, guilds: Parameters["1"]): Promise; /** * Send an OP 43 REQUEST_CHANNEL_INFO to Discord. * @param shardId id of the shard that should send the payload. * @param data Request channel info data to send. * @returns Promise that's resolved once the payload was send to Discord. * * @example * // Connect to Discord and request channel info. * 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 channel info payload. * // We will use shard 0 as the shard to send the payload. * client.requestChannelInfo(0, ["id"]); * }); */ requestChannelInfo(shardId: number, data: Parameters["1"]): Promise; /** * Update the endpoint shard websockets will connect to. * @since 0.1.4 * @param gatewayUrl Base gateway wss url to update the cached endpoint to. */ private _updateEndpoint; } export = Client;