Skip to content

Commit a041723

Browse files
feat: Add gateway endpoints (#11130)
feat: add gateway Co-Authored-By: kodiakhq[bot] <49736102+kodiakhq[bot]@users.noreply.github.com>
1 parent 154c00d commit a041723

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

packages/core/src/api/gateway.ts

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/* eslint-disable jsdoc/check-param-names */
2+
3+
import type { RequestData, REST } from '@discordjs/rest';
4+
import { Routes, type RESTGetAPIGatewayBotResult, type RESTGetAPIGatewayResult } from 'discord-api-types/v10';
5+
6+
export class GatewayAPI {
7+
public constructor(private readonly rest: REST) {}
8+
9+
/**
10+
* Gets gateway information.
11+
*
12+
* @see {@link https://discord.com/developers/docs/events/gateway#get-gateway}
13+
* @param options - The options for fetching the gateway information
14+
*/
15+
public async get({ signal }: Pick<RequestData, 'signal'> = {}) {
16+
return this.rest.get(Routes.gateway(), {
17+
auth: false,
18+
signal,
19+
}) as Promise<RESTGetAPIGatewayResult>;
20+
}
21+
22+
/**
23+
* Gets gateway information with additional metadata.
24+
*
25+
* @see {@link https://discord.com/developers/docs/events/gateway#get-gateway-bot}
26+
* @param options - The options for fetching the gateway information
27+
*/
28+
public async getBot({ signal }: Pick<RequestData, 'signal'> = {}) {
29+
return this.rest.get(Routes.gatewayBot(), { signal }) as Promise<RESTGetAPIGatewayBotResult>;
30+
}
31+
}

packages/core/src/api/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import type { REST } from '@discordjs/rest';
22
import { ApplicationCommandsAPI } from './applicationCommands.js';
33
import { ApplicationsAPI } from './applications.js';
44
import { ChannelsAPI } from './channel.js';
5+
import { GatewayAPI } from './gateway.js';
56
import { GuildsAPI } from './guild.js';
67
import { InteractionsAPI } from './interactions.js';
78
import { InvitesAPI } from './invite.js';
@@ -19,6 +20,7 @@ import { WebhooksAPI } from './webhook.js';
1920
export * from './applicationCommands.js';
2021
export * from './applications.js';
2122
export * from './channel.js';
23+
export * from './gateway.js';
2224
export * from './guild.js';
2325
export * from './interactions.js';
2426
export * from './invite.js';
@@ -40,6 +42,8 @@ export class API {
4042

4143
public readonly channels: ChannelsAPI;
4244

45+
public readonly gateway: GatewayAPI;
46+
4347
public readonly guilds: GuildsAPI;
4448

4549
public readonly interactions: InteractionsAPI;
@@ -70,6 +74,7 @@ export class API {
7074
this.applicationCommands = new ApplicationCommandsAPI(rest);
7175
this.applications = new ApplicationsAPI(rest);
7276
this.channels = new ChannelsAPI(rest);
77+
this.gateway = new GatewayAPI(rest);
7378
this.guilds = new GuildsAPI(rest);
7479
this.invites = new InvitesAPI(rest);
7580
this.monetization = new MonetizationAPI(rest);

0 commit comments

Comments
 (0)