mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
feat: Add gateway endpoints (#11130)
feat: add gateway Co-Authored-By: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
This commit is contained in:
31
packages/core/src/api/gateway.ts
Normal file
31
packages/core/src/api/gateway.ts
Normal file
@@ -0,0 +1,31 @@
|
|||||||
|
/* eslint-disable jsdoc/check-param-names */
|
||||||
|
|
||||||
|
import type { RequestData, REST } from '@discordjs/rest';
|
||||||
|
import { Routes, type RESTGetAPIGatewayBotResult, type RESTGetAPIGatewayResult } from 'discord-api-types/v10';
|
||||||
|
|
||||||
|
export class GatewayAPI {
|
||||||
|
public constructor(private readonly rest: REST) {}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets gateway information.
|
||||||
|
*
|
||||||
|
* @see {@link https://discord.com/developers/docs/events/gateway#get-gateway}
|
||||||
|
* @param options - The options for fetching the gateway information
|
||||||
|
*/
|
||||||
|
public async get({ signal }: Pick<RequestData, 'signal'> = {}) {
|
||||||
|
return this.rest.get(Routes.gateway(), {
|
||||||
|
auth: false,
|
||||||
|
signal,
|
||||||
|
}) as Promise<RESTGetAPIGatewayResult>;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Gets gateway information with additional metadata.
|
||||||
|
*
|
||||||
|
* @see {@link https://discord.com/developers/docs/events/gateway#get-gateway-bot}
|
||||||
|
* @param options - The options for fetching the gateway information
|
||||||
|
*/
|
||||||
|
public async getBot({ signal }: Pick<RequestData, 'signal'> = {}) {
|
||||||
|
return this.rest.get(Routes.gatewayBot(), { signal }) as Promise<RESTGetAPIGatewayBotResult>;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -2,6 +2,7 @@ import type { REST } from '@discordjs/rest';
|
|||||||
import { ApplicationCommandsAPI } from './applicationCommands.js';
|
import { ApplicationCommandsAPI } from './applicationCommands.js';
|
||||||
import { ApplicationsAPI } from './applications.js';
|
import { ApplicationsAPI } from './applications.js';
|
||||||
import { ChannelsAPI } from './channel.js';
|
import { ChannelsAPI } from './channel.js';
|
||||||
|
import { GatewayAPI } from './gateway.js';
|
||||||
import { GuildsAPI } from './guild.js';
|
import { GuildsAPI } from './guild.js';
|
||||||
import { InteractionsAPI } from './interactions.js';
|
import { InteractionsAPI } from './interactions.js';
|
||||||
import { InvitesAPI } from './invite.js';
|
import { InvitesAPI } from './invite.js';
|
||||||
@@ -19,6 +20,7 @@ import { WebhooksAPI } from './webhook.js';
|
|||||||
export * from './applicationCommands.js';
|
export * from './applicationCommands.js';
|
||||||
export * from './applications.js';
|
export * from './applications.js';
|
||||||
export * from './channel.js';
|
export * from './channel.js';
|
||||||
|
export * from './gateway.js';
|
||||||
export * from './guild.js';
|
export * from './guild.js';
|
||||||
export * from './interactions.js';
|
export * from './interactions.js';
|
||||||
export * from './invite.js';
|
export * from './invite.js';
|
||||||
@@ -40,6 +42,8 @@ export class API {
|
|||||||
|
|
||||||
public readonly channels: ChannelsAPI;
|
public readonly channels: ChannelsAPI;
|
||||||
|
|
||||||
|
public readonly gateway: GatewayAPI;
|
||||||
|
|
||||||
public readonly guilds: GuildsAPI;
|
public readonly guilds: GuildsAPI;
|
||||||
|
|
||||||
public readonly interactions: InteractionsAPI;
|
public readonly interactions: InteractionsAPI;
|
||||||
@@ -70,6 +74,7 @@ export class API {
|
|||||||
this.applicationCommands = new ApplicationCommandsAPI(rest);
|
this.applicationCommands = new ApplicationCommandsAPI(rest);
|
||||||
this.applications = new ApplicationsAPI(rest);
|
this.applications = new ApplicationsAPI(rest);
|
||||||
this.channels = new ChannelsAPI(rest);
|
this.channels = new ChannelsAPI(rest);
|
||||||
|
this.gateway = new GatewayAPI(rest);
|
||||||
this.guilds = new GuildsAPI(rest);
|
this.guilds = new GuildsAPI(rest);
|
||||||
this.invites = new InvitesAPI(rest);
|
this.invites = new InvitesAPI(rest);
|
||||||
this.monetization = new MonetizationAPI(rest);
|
this.monetization = new MonetizationAPI(rest);
|
||||||
|
|||||||
Reference in New Issue
Block a user