From 7b1b70d5514a857db967f935ea87f1f2469ee6ca Mon Sep 17 00:00:00 2001 From: Danial Raza Date: Thu, 10 Sep 2026 20:07:58 +0200 Subject: [PATCH] feat: add per-request `dispatcher`, `headers` and `rejectOnRateLimit` --- packages/core/src/api/applicationCommands.ts | 91 ++- packages/core/src/api/applications.ts | 56 +- packages/core/src/api/channel.ts | 230 +++++-- packages/core/src/api/gateway.ts | 13 +- packages/core/src/api/guild.ts | 613 +++++++++++++++---- packages/core/src/api/interactions.ts | 108 ++-- packages/core/src/api/invite.ts | 22 +- packages/core/src/api/monetization.ts | 61 +- packages/core/src/api/oauth2.ts | 45 +- packages/core/src/api/poll.ts | 13 +- packages/core/src/api/roleConnections.ts | 13 +- packages/core/src/api/soundboardSounds.ts | 14 +- packages/core/src/api/stageInstances.ts | 37 +- packages/core/src/api/sticker.ts | 39 +- packages/core/src/api/thread.ts | 63 +- packages/core/src/api/user.ts | 92 ++- packages/core/src/api/voice.ts | 36 +- packages/core/src/api/webhook.ts | 66 +- packages/core/src/util/index.ts | 1 + packages/core/src/util/types.ts | 21 + packages/rest/src/lib/utils/types.ts | 4 +- 21 files changed, 1318 insertions(+), 320 deletions(-) create mode 100644 packages/core/src/util/types.ts diff --git a/packages/core/src/api/applicationCommands.ts b/packages/core/src/api/applicationCommands.ts index 5c39e40cd..effa4e4a7 100644 --- a/packages/core/src/api/applicationCommands.ts +++ b/packages/core/src/api/applicationCommands.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest'; +import { makeURLSearchParams, type REST } from '@discordjs/rest'; import { Routes, type Locale, @@ -28,6 +28,7 @@ import { type RESTPutAPIApplicationGuildCommandsResult, type Snowflake, } from 'discord-api-types/v10'; +import type { BaseRequestOptions, RequestOptions } from '../util/types.js'; export class ApplicationCommandsAPI { public constructor(private readonly rest: REST) {} @@ -43,12 +44,14 @@ export class ApplicationCommandsAPI { public async getGlobalCommands( applicationId: Snowflake, query: RESTGetAPIApplicationCommandsQuery = {}, - { auth, locale, signal }: Pick & { locale?: Locale } = {}, + { auth, dispatcher, headers, locale, rejectOnRateLimit, signal }: RequestOptions & { locale?: Locale } = {}, ) { return this.rest.get(Routes.applicationCommands(applicationId), { auth, - headers: locale ? { 'X-Discord-Locale': locale } : {}, + headers: locale ? { ...headers, 'X-Discord-Locale': locale } : headers, query: makeURLSearchParams(query), + dispatcher, + rejectOnRateLimit, signal, }) as Promise; } @@ -64,11 +67,14 @@ export class ApplicationCommandsAPI { public async createGlobalCommand( applicationId: Snowflake, body: RESTPostAPIApplicationCommandsJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.post(Routes.applicationCommands(applicationId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -84,10 +90,13 @@ export class ApplicationCommandsAPI { public async getGlobalCommand( applicationId: Snowflake, commandId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.applicationCommand(applicationId, commandId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -105,11 +114,14 @@ export class ApplicationCommandsAPI { applicationId: Snowflake, commandId: Snowflake, body: RESTPatchAPIApplicationCommandJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.patch(Routes.applicationCommand(applicationId, commandId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -125,9 +137,15 @@ export class ApplicationCommandsAPI { public async deleteGlobalCommand( applicationId: Snowflake, commandId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - await this.rest.delete(Routes.applicationCommand(applicationId, commandId), { auth, signal }); + await this.rest.delete(Routes.applicationCommand(applicationId, commandId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }); } /** @@ -141,11 +159,14 @@ export class ApplicationCommandsAPI { public async bulkOverwriteGlobalCommands( applicationId: Snowflake, body: RESTPutAPIApplicationCommandsJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.put(Routes.applicationCommands(applicationId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -163,12 +184,14 @@ export class ApplicationCommandsAPI { applicationId: Snowflake, guildId: Snowflake, query: RESTGetAPIApplicationGuildCommandsQuery = {}, - { auth, locale, signal }: Pick & { locale?: Locale } = {}, + { auth, dispatcher, headers, locale, rejectOnRateLimit, signal }: RequestOptions & { locale?: Locale } = {}, ) { return this.rest.get(Routes.applicationGuildCommands(applicationId, guildId), { auth, - headers: locale ? { 'X-Discord-Locale': locale } : {}, + headers: locale ? { ...headers, 'X-Discord-Locale': locale } : headers, query: makeURLSearchParams(query), + dispatcher, + rejectOnRateLimit, signal, }) as Promise; } @@ -186,11 +209,14 @@ export class ApplicationCommandsAPI { applicationId: Snowflake, guildId: Snowflake, body: RESTPostAPIApplicationGuildCommandsJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.post(Routes.applicationGuildCommands(applicationId, guildId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -208,10 +234,13 @@ export class ApplicationCommandsAPI { applicationId: Snowflake, guildId: Snowflake, commandId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.applicationGuildCommand(applicationId, guildId, commandId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -231,11 +260,14 @@ export class ApplicationCommandsAPI { guildId: Snowflake, commandId: Snowflake, body: RESTPatchAPIApplicationGuildCommandJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.patch(Routes.applicationGuildCommand(applicationId, guildId, commandId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -253,9 +285,15 @@ export class ApplicationCommandsAPI { applicationId: Snowflake, guildId: Snowflake, commandId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - await this.rest.delete(Routes.applicationGuildCommand(applicationId, guildId, commandId), { auth, signal }); + await this.rest.delete(Routes.applicationGuildCommand(applicationId, guildId, commandId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }); } /** @@ -271,11 +309,14 @@ export class ApplicationCommandsAPI { applicationId: Snowflake, guildId: Snowflake, body: RESTPutAPIApplicationGuildCommandsJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.put(Routes.applicationGuildCommands(applicationId, guildId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -293,10 +334,13 @@ export class ApplicationCommandsAPI { applicationId: Snowflake, guildId: Snowflake, commandId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.applicationCommandPermissions(applicationId, guildId, commandId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -312,10 +356,13 @@ export class ApplicationCommandsAPI { public async getGuildCommandsPermissions( applicationId: Snowflake, guildId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildApplicationCommandsPermissions(applicationId, guildId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -337,12 +384,14 @@ export class ApplicationCommandsAPI { guildId: Snowflake, commandId: Snowflake, body: RESTPutAPIApplicationCommandPermissionsJSONBody, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { return this.rest.put(Routes.applicationCommandPermissions(applicationId, guildId, commandId), { - headers: { Authorization: `Bearer ${userToken.replace('Bearer ', '')}` }, + headers: { ...headers, Authorization: `Bearer ${userToken.replace('Bearer ', '')}` }, auth: false, body, + dispatcher, + rejectOnRateLimit, signal, }) as Promise; } diff --git a/packages/core/src/api/applications.ts b/packages/core/src/api/applications.ts index df6322eef..dd88334ca 100644 --- a/packages/core/src/api/applications.ts +++ b/packages/core/src/api/applications.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import type { RequestData, REST } from '@discordjs/rest'; +import type { REST } from '@discordjs/rest'; import { Routes, type RESTGetAPIApplicationActivityInstanceResult, @@ -15,6 +15,7 @@ import { type RESTPostAPIApplicationEmojiResult, type Snowflake, } from 'discord-api-types/v10'; +import type { RequestOptions } from '../util/types.js'; export class ApplicationsAPI { public constructor(private readonly rest: REST) {} @@ -25,8 +26,14 @@ export class ApplicationsAPI { * @see {@link https://discord.com/developers/docs/resources/application#get-current-application} * @param options - The options for fetching the application */ - public async getCurrent({ auth, signal }: Pick = {}) { - return this.rest.get(Routes.currentApplication(), { auth, signal }) as Promise; + public async getCurrent({ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) { + return this.rest.get(Routes.currentApplication(), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -38,11 +45,14 @@ export class ApplicationsAPI { */ public async editCurrent( body: RESTPatchCurrentApplicationJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.patch(Routes.currentApplication(), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -54,9 +64,15 @@ export class ApplicationsAPI { * @param applicationId - The id of the application to fetch the emojis of * @param options - The options for fetching the emojis */ - public async getEmojis(applicationId: Snowflake, { auth, signal }: Pick = {}) { + public async getEmojis( + applicationId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.applicationEmojis(applicationId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -72,10 +88,13 @@ export class ApplicationsAPI { public async getEmoji( applicationId: Snowflake, emojiId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.applicationEmoji(applicationId, emojiId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -91,11 +110,14 @@ export class ApplicationsAPI { public async createEmoji( applicationId: Snowflake, body: RESTPostAPIApplicationEmojiJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.post(Routes.applicationEmojis(applicationId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -113,11 +135,14 @@ export class ApplicationsAPI { applicationId: Snowflake, emojiId: Snowflake, body: RESTPatchAPIApplicationEmojiJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.patch(Routes.applicationEmoji(applicationId, emojiId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -133,9 +158,15 @@ export class ApplicationsAPI { public async deleteEmoji( applicationId: Snowflake, emojiId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - await this.rest.delete(Routes.applicationEmoji(applicationId, emojiId), { auth, signal }); + await this.rest.delete(Routes.applicationEmoji(applicationId, emojiId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }); } /** @@ -149,10 +180,13 @@ export class ApplicationsAPI { public async getActivityInstance( applicationId: Snowflake, instanceId: string, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.applicationActivityInstance(applicationId, instanceId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } diff --git a/packages/core/src/api/channel.ts b/packages/core/src/api/channel.ts index 1490fc718..b2ccc8d16 100644 --- a/packages/core/src/api/channel.ts +++ b/packages/core/src/api/channel.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import { makeURLSearchParams, type RawFile, type RequestData, type REST } from '@discordjs/rest'; +import { makeURLSearchParams, type RawFile, type REST } from '@discordjs/rest'; import { Routes, type RESTDeleteAPIChannelResult, @@ -36,6 +36,7 @@ import { type RESTPutAPIChannelRecipientJSONBody, type Snowflake, } from 'discord-api-types/v10'; +import type { RequestOptions, RequestOptionsWithReason } from '../util/types.js'; export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody { message: RESTPostAPIGuildForumThreadsJSONBody['message'] & { files?: RawFile[] }; @@ -63,12 +64,15 @@ export class ChannelsAPI { public async createMessage( channelId: Snowflake, { files, ...body }: CreateMessageOptions, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.post(Routes.channelMessages(channelId), { auth, files, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -86,12 +90,15 @@ export class ChannelsAPI { channelId: Snowflake, messageId: Snowflake, { files, ...body }: EditMessageOptions, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.patch(Routes.channelMessage(channelId, messageId), { auth, files, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -119,11 +126,14 @@ export class ChannelsAPI { messageId: Snowflake, emoji: string, query: RESTGetAPIChannelMessageReactionUsersQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.channelMessageReaction(channelId, messageId, encodeURIComponent(emoji)), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -149,10 +159,13 @@ export class ChannelsAPI { channelId: Snowflake, messageId: Snowflake, emoji: string, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { await this.rest.delete(Routes.channelMessageOwnReaction(channelId, messageId, encodeURIComponent(emoji)), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }); } @@ -180,10 +193,13 @@ export class ChannelsAPI { messageId: Snowflake, emoji: string, userId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { await this.rest.delete(Routes.channelMessageUserReaction(channelId, messageId, encodeURIComponent(emoji), userId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }); } @@ -199,9 +215,15 @@ export class ChannelsAPI { public async deleteAllMessageReactions( channelId: Snowflake, messageId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - await this.rest.delete(Routes.channelMessageAllReactions(channelId, messageId), { auth, signal }); + await this.rest.delete(Routes.channelMessageAllReactions(channelId, messageId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }); } /** @@ -225,10 +247,13 @@ export class ChannelsAPI { channelId: Snowflake, messageId: Snowflake, emoji: string, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { await this.rest.delete(Routes.channelMessageReaction(channelId, messageId, encodeURIComponent(emoji)), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }); } @@ -254,10 +279,13 @@ export class ChannelsAPI { channelId: Snowflake, messageId: Snowflake, emoji: string, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { await this.rest.put(Routes.channelMessageOwnReaction(channelId, messageId, encodeURIComponent(emoji)), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }); } @@ -269,8 +297,17 @@ export class ChannelsAPI { * @param channelId - The id of the channel * @param options - The options for fetching the channel */ - public async get(channelId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.channel(channelId), { auth, signal }) as Promise; + public async get( + channelId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.channel(channelId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -284,12 +321,15 @@ export class ChannelsAPI { public async edit( channelId: Snowflake, body: RESTPatchAPIChannelJSONBody, - { auth, signal, reason }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.channel(channelId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -303,9 +343,16 @@ export class ChannelsAPI { */ public async delete( channelId: Snowflake, - { auth, signal, reason }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - return this.rest.delete(Routes.channel(channelId), { auth, signal, reason }) as Promise; + return this.rest.delete(Routes.channel(channelId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -319,11 +366,14 @@ export class ChannelsAPI { public async getMessages( channelId: Snowflake, query: RESTGetAPIChannelMessagesQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.channelMessages(channelId), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -335,8 +385,11 @@ export class ChannelsAPI { * @param channelId - The id of the channel to show the typing indicator in * @param options - The options for showing the typing indicator */ - public async showTyping(channelId: Snowflake, { auth, signal }: Pick = {}) { - await this.rest.post(Routes.channelTyping(channelId), { auth, signal }); + public async showTyping( + channelId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + await this.rest.post(Routes.channelTyping(channelId), { auth, dispatcher, headers, rejectOnRateLimit, signal }); } /** @@ -350,11 +403,14 @@ export class ChannelsAPI { public async getPins( channelId: Snowflake, query: RESTGetAPIChannelMessagesPinsQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.channelMessagesPins(channelId), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -370,9 +426,16 @@ export class ChannelsAPI { public async pinMessage( channelId: Snowflake, messageId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.put(Routes.channelMessagesPin(channelId, messageId), { auth, reason, signal }); + await this.rest.put(Routes.channelMessagesPin(channelId, messageId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -386,9 +449,16 @@ export class ChannelsAPI { public async deleteMessage( channelId: Snowflake, messageId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.channelMessage(channelId, messageId), { auth, reason, signal }); + await this.rest.delete(Routes.channelMessage(channelId, messageId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -402,9 +472,17 @@ export class ChannelsAPI { public async bulkDeleteMessages( channelId: Snowflake, messageIds: Snowflake[], - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ): Promise { - await this.rest.post(Routes.channelBulkDelete(channelId), { auth, reason, body: { messages: messageIds }, signal }); + await this.rest.post(Routes.channelBulkDelete(channelId), { + auth, + body: { messages: messageIds }, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -418,10 +496,13 @@ export class ChannelsAPI { public async getMessage( channelId: Snowflake, messageId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.channelMessage(channelId, messageId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -437,10 +518,13 @@ export class ChannelsAPI { public async crosspostMessage( channelId: Snowflake, messageId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.post(Routes.channelMessageCrosspost(channelId, messageId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -456,9 +540,16 @@ export class ChannelsAPI { public async unpinMessage( channelId: Snowflake, messageId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.channelMessagesPin(channelId, messageId), { auth, reason, signal }); + await this.rest.delete(Routes.channelMessagesPin(channelId, messageId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -472,12 +563,15 @@ export class ChannelsAPI { public async followAnnouncements( channelId: Snowflake, webhookChannelId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.channelFollowers(channelId), { auth, body: { webhook_channel_id: webhookChannelId }, reason, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -493,12 +587,15 @@ export class ChannelsAPI { public async createInvite( channelId: Snowflake, body: RESTPostAPIChannelInviteJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.channelInvites(channelId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -510,8 +607,17 @@ export class ChannelsAPI { * @param channelId - The id of the channel to fetch invites from * @param options - The options for fetching the invites */ - public async getInvites(channelId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.channelInvites(channelId), { auth, signal }) as Promise; + public async getInvites( + channelId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.channelInvites(channelId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -528,11 +634,14 @@ export class ChannelsAPI { channelId: Snowflake, body: RESTPostAPIChannelThreadsJSONBody, messageId?: Snowflake, - { auth, signal, reason }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.threads(channelId, messageId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, reason, }) as Promise; @@ -549,7 +658,7 @@ export class ChannelsAPI { public async createForumThread( channelId: Snowflake, { message, ...optionsBody }: StartForumThreadOptions, - { auth, signal, reason }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { const { files, ...messageBody } = message; @@ -563,6 +672,9 @@ export class ChannelsAPI { files, body, reason, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -581,11 +693,14 @@ export class ChannelsAPI { channelId: Snowflake, archivedStatus: 'private' | 'public', query: RESTGetAPIChannelThreadsArchivedQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.channelThreads(channelId, archivedStatus), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -601,11 +716,14 @@ export class ChannelsAPI { public async getJoinedPrivateArchivedThreads( channelId: Snowflake, query: RESTGetAPIChannelThreadsArchivedQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.channelJoinedArchivedThreads(channelId), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -621,12 +739,15 @@ export class ChannelsAPI { public async createWebhook( channelId: Snowflake, body: RESTPostAPIChannelWebhookJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.channelWebhooks(channelId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -638,9 +759,15 @@ export class ChannelsAPI { * @param channelId - The id of the channel * @param options - The options for fetching the webhooks */ - public async getWebhooks(channelId: Snowflake, { auth, signal }: Pick = {}) { + public async getWebhooks( + channelId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.channelWebhooks(channelId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -658,12 +785,15 @@ export class ChannelsAPI { channelId: Snowflake, overwriteId: Snowflake, body: RESTPutAPIChannelPermissionJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { await this.rest.put(Routes.channelPermission(channelId, overwriteId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }); } @@ -679,11 +809,14 @@ export class ChannelsAPI { public async deletePermissionOverwrite( channelId: Snowflake, overwriteId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { await this.rest.delete(Routes.channelPermission(channelId, overwriteId), { auth, reason, + dispatcher, + headers, + rejectOnRateLimit, signal, }); } @@ -699,11 +832,14 @@ export class ChannelsAPI { public async sendSoundboardSound( channelId: Snowflake, body: RESTPostAPISoundboardSendSoundJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { await this.rest.post(Routes.sendSoundboardSound(channelId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }); } @@ -721,11 +857,14 @@ export class ChannelsAPI { channelId: Snowflake, userId: Snowflake, body: RESTPutAPIChannelRecipientJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { await this.rest.put(Routes.channelRecipient(channelId, userId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }); } @@ -741,10 +880,13 @@ export class ChannelsAPI { public async removeGroupDMRecipient( channelId: Snowflake, userId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { await this.rest.delete(Routes.channelRecipient(channelId, userId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }); } diff --git a/packages/core/src/api/gateway.ts b/packages/core/src/api/gateway.ts index 5eccff05e..7c31d2048 100644 --- a/packages/core/src/api/gateway.ts +++ b/packages/core/src/api/gateway.ts @@ -1,7 +1,8 @@ /* eslint-disable jsdoc/check-param-names */ -import type { RequestData, REST } from '@discordjs/rest'; +import type { REST } from '@discordjs/rest'; import { Routes, type RESTGetAPIGatewayBotResult, type RESTGetAPIGatewayResult } from 'discord-api-types/v10'; +import type { BaseRequestOptions, RequestOptions } from '../util/types.js'; export class GatewayAPI { public constructor(private readonly rest: REST) {} @@ -12,9 +13,12 @@ export class GatewayAPI { * @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 = {}) { + public async get({ dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}) { return this.rest.get(Routes.gateway(), { auth: false, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -25,9 +29,12 @@ export class GatewayAPI { * @see {@link https://discord.com/developers/docs/events/gateway#get-gateway-bot} * @param options - The options for fetching the gateway information */ - public async getBot({ auth, signal }: Pick = {}) { + public async getBot({ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) { return this.rest.get(Routes.gatewayBot(), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } diff --git a/packages/core/src/api/guild.ts b/packages/core/src/api/guild.ts index 1c77ffc7f..7d87ea87a 100644 --- a/packages/core/src/api/guild.ts +++ b/packages/core/src/api/guild.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import { makeURLSearchParams, type REST, type RawFile, type RequestData } from '@discordjs/rest'; +import { makeURLSearchParams, type REST, type RawFile } from '@discordjs/rest'; import { Routes, type GuildWidgetStyle, @@ -107,6 +107,7 @@ import { type RESTPutAPIGuildTemplateSyncResult, type Snowflake, } from 'discord-api-types/v10'; +import type { RequestOptions, RequestOptionsWithReason } from '../util/types.js'; export interface CreateStickerOptions extends Omit { file: RawFile; @@ -126,11 +127,14 @@ export class GuildsAPI { public async get( guildId: Snowflake, query: RESTGetAPIGuildQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guild(guildId), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -142,9 +146,15 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the preview from * @param options - The options for fetching the guild preview */ - public async getPreview(guildId: Snowflake, { auth, signal }: Pick = {}) { + public async getPreview( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.guildPreview(guildId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -160,12 +170,15 @@ export class GuildsAPI { public async edit( guildId: Snowflake, body: RESTPatchAPIGuildJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guild(guildId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -183,11 +196,14 @@ export class GuildsAPI { guildId: Snowflake, userId: Snowflake, body: RESTPutAPIGuildMemberJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.put(Routes.guildMember(guildId, userId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -203,11 +219,14 @@ export class GuildsAPI { public async getMembers( guildId: Snowflake, query: RESTGetAPIGuildMembersQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildMembers(guildId), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -219,9 +238,15 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the channels from * @param options - The options for fetching the guild channels */ - public async getChannels(guildId: Snowflake, { auth, signal }: Pick = {}) { + public async getChannels( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.guildChannels(guildId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -237,12 +262,15 @@ export class GuildsAPI { public async createChannel( guildId: Snowflake, body: RESTPostAPIGuildChannelJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.guildChannels(guildId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -258,9 +286,17 @@ export class GuildsAPI { public async setChannelPositions( guildId: Snowflake, body: RESTPatchAPIGuildChannelPositionsJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.patch(Routes.guildChannels(guildId), { auth, reason, body, signal }); + await this.rest.patch(Routes.guildChannels(guildId), { + auth, + body, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -270,8 +306,17 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the active threads from * @param options - The options for fetching the active threads */ - public async getActiveThreads(guildId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.guildActiveThreads(guildId), { auth, signal }) as Promise; + public async getActiveThreads( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.guildActiveThreads(guildId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -285,9 +330,15 @@ export class GuildsAPI { public async getMemberBan( guildId: Snowflake, userId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - return this.rest.get(Routes.guildBan(guildId, userId), { auth, signal }) as Promise; + return this.rest.get(Routes.guildBan(guildId, userId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -301,11 +352,14 @@ export class GuildsAPI { public async getMemberBans( guildId: Snowflake, query: RESTGetAPIGuildBansQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildBans(guildId), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -323,9 +377,17 @@ export class GuildsAPI { guildId: Snowflake, userId: Snowflake, body: RESTPutAPIGuildBanJSONBody = {}, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.put(Routes.guildBan(guildId, userId), { auth, reason, body, signal }); + await this.rest.put(Routes.guildBan(guildId, userId), { + auth, + body, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -339,9 +401,16 @@ export class GuildsAPI { public async unbanUser( guildId: Snowflake, userId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.guildBan(guildId, userId), { auth, reason, signal }); + await this.rest.delete(Routes.guildBan(guildId, userId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -355,12 +424,15 @@ export class GuildsAPI { public async bulkBanUsers( guildId: Snowflake, body: RESTPostAPIGuildBulkBanJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.guildBulkBan(guildId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -372,8 +444,17 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the roles from * @param options - The options for fetching the guild roles */ - public async getRoles(guildId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.guildRoles(guildId), { auth, signal }) as Promise; + public async getRoles( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.guildRoles(guildId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -387,9 +468,15 @@ export class GuildsAPI { public async getRole( guildId: Snowflake, roleId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - return this.rest.get(Routes.guildRole(guildId, roleId), { auth, signal }) as Promise; + return this.rest.get(Routes.guildRole(guildId, roleId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -403,12 +490,15 @@ export class GuildsAPI { public async createRole( guildId: Snowflake, body: RESTPostAPIGuildRoleJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.guildRoles(guildId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -424,12 +514,15 @@ export class GuildsAPI { public async setRolePositions( guildId: Snowflake, body: RESTPatchAPIGuildRolePositionsJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guildRoles(guildId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -447,12 +540,15 @@ export class GuildsAPI { guildId: Snowflake, roleId: Snowflake, body: RESTPatchAPIGuildRoleJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guildRole(guildId, roleId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -468,9 +564,16 @@ export class GuildsAPI { public async deleteRole( guildId: Snowflake, roleId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.guildRole(guildId, roleId), { auth, reason, signal }); + await this.rest.delete(Routes.guildRole(guildId, roleId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -484,10 +587,13 @@ export class GuildsAPI { public async getPruneCount( guildId: Snowflake, query: RESTGetAPIGuildPruneCountQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildPrune(guildId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, query: makeURLSearchParams(query), }) as Promise; @@ -504,12 +610,15 @@ export class GuildsAPI { public async beginPrune( guildId: Snowflake, body: RESTPostAPIGuildPruneJSONBody = {}, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.guildPrune(guildId), { auth, body, reason, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -521,9 +630,15 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the voice regions from * @param options - The options for fetching the voice regions */ - public async getVoiceRegions(guildId: Snowflake, { auth, signal }: Pick = {}) { + public async getVoiceRegions( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.guildVoiceRegions(guildId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -535,8 +650,17 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the invites from * @param options - The options for fetching the invites */ - public async getInvites(guildId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.guildInvites(guildId), { auth, signal }) as Promise; + public async getInvites( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.guildInvites(guildId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -546,9 +670,15 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the integrations from * @param options - The options for fetching the integrations */ - public async getIntegrations(guildId: Snowflake, { auth, signal }: Pick = {}) { + public async getIntegrations( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.guildIntegrations(guildId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -564,9 +694,16 @@ export class GuildsAPI { public async deleteIntegration( guildId: Snowflake, integrationId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.guildIntegration(guildId, integrationId), { auth, reason, signal }); + await this.rest.delete(Routes.guildIntegration(guildId, integrationId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -576,9 +713,15 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the widget settings from * @param options - The options for fetching the widget settings */ - public async getWidgetSettings(guildId: Snowflake, { auth, signal }: Pick = {}) { + public async getWidgetSettings( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.guildWidgetSettings(guildId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -594,12 +737,15 @@ export class GuildsAPI { public async editWidgetSettings( guildId: Snowflake, body: RESTPatchAPIGuildWidgetSettingsJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guildWidgetSettings(guildId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -611,8 +757,17 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the widget from * @param options - The options for fetching the widget */ - public async getWidget(guildId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.guildWidgetJSON(guildId), { auth, signal }) as Promise; + public async getWidget( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.guildWidgetJSON(guildId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -622,8 +777,17 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the vanity url from * @param options - The options for fetching the vanity url */ - public async getVanityURL(guildId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.guildVanityUrl(guildId), { auth, signal }) as Promise; + public async getVanityURL( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.guildVanityUrl(guildId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -637,11 +801,14 @@ export class GuildsAPI { public async getWidgetImage( guildId: Snowflake, style?: GuildWidgetStyle, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildWidgetImage(guildId), { auth, query: makeURLSearchParams({ style }), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -653,9 +820,15 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the welcome screen from * @param options - The options for fetching the welcome screen */ - public async getWelcomeScreen(guildId: Snowflake, { auth, signal }: Pick = {}) { + public async getWelcomeScreen( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.guildWelcomeScreen(guildId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -671,12 +844,15 @@ export class GuildsAPI { public async editWelcomeScreen( guildId: Snowflake, body?: RESTPatchAPIGuildWelcomeScreenJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guildWelcomeScreen(guildId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -688,8 +864,17 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the emojis from * @param options - The options for fetching the emojis */ - public async getEmojis(guildId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.guildEmojis(guildId), { auth, signal }) as Promise; + public async getEmojis( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.guildEmojis(guildId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -703,9 +888,15 @@ export class GuildsAPI { public async getEmoji( guildId: Snowflake, emojiId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - return this.rest.get(Routes.guildEmoji(guildId, emojiId), { auth, signal }) as Promise; + return this.rest.get(Routes.guildEmoji(guildId, emojiId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -719,12 +910,15 @@ export class GuildsAPI { public async createEmoji( guildId: Snowflake, body: RESTPostAPIGuildEmojiJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.guildEmojis(guildId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -742,12 +936,15 @@ export class GuildsAPI { guildId: Snowflake, emojiId: Snowflake, body: RESTPatchAPIGuildEmojiJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guildEmoji(guildId, emojiId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -763,9 +960,16 @@ export class GuildsAPI { public async deleteEmoji( guildId: Snowflake, emojiId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.guildEmoji(guildId, emojiId), { auth, reason, signal }); + await this.rest.delete(Routes.guildEmoji(guildId, emojiId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -779,11 +983,14 @@ export class GuildsAPI { public async getScheduledEvents( guildId: Snowflake, query: RESTGetAPIGuildScheduledEventsQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildScheduledEvents(guildId), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -799,12 +1006,15 @@ export class GuildsAPI { public async createScheduledEvent( guildId: Snowflake, body: RESTPostAPIGuildScheduledEventJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.guildScheduledEvents(guildId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -822,11 +1032,14 @@ export class GuildsAPI { guildId: Snowflake, eventId: Snowflake, query: RESTGetAPIGuildScheduledEventQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildScheduledEvent(guildId, eventId), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -844,12 +1057,15 @@ export class GuildsAPI { guildId: Snowflake, eventId: Snowflake, body: RESTPatchAPIGuildScheduledEventJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guildScheduledEvent(guildId, eventId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -865,9 +1081,16 @@ export class GuildsAPI { public async deleteScheduledEvent( guildId: Snowflake, eventId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.guildScheduledEvent(guildId, eventId), { auth, reason, signal }); + await this.rest.delete(Routes.guildScheduledEvent(guildId, eventId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -883,11 +1106,14 @@ export class GuildsAPI { guildId: Snowflake, eventId: Snowflake, query: RESTGetAPIGuildScheduledEventUsersQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildScheduledEventUsers(guildId, eventId), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -899,8 +1125,17 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the templates from * @param options - The options for fetching the templates */ - public async getTemplates(guildId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.guildTemplates(guildId), { auth, signal }) as Promise; + public async getTemplates( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.guildTemplates(guildId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -914,10 +1149,13 @@ export class GuildsAPI { public async syncTemplate( guildId: Snowflake, templateCode: string, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.put(Routes.guildTemplate(guildId, templateCode), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -935,11 +1173,14 @@ export class GuildsAPI { guildId: Snowflake, templateCode: string, body: RESTPatchAPIGuildTemplateJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.patch(Routes.guildTemplate(guildId, templateCode), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -955,9 +1196,15 @@ export class GuildsAPI { public async deleteTemplate( guildId: Snowflake, templateCode: string, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - await this.rest.delete(Routes.guildTemplate(guildId, templateCode), { auth, signal }); + await this.rest.delete(Routes.guildTemplate(guildId, templateCode), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }); } /** @@ -967,8 +1214,17 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the stickers from * @param options - The options for fetching the stickers */ - public async getStickers(guildId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.guildStickers(guildId), { auth, signal }) as Promise; + public async getStickers( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.guildStickers(guildId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -982,10 +1238,13 @@ export class GuildsAPI { public async getSticker( guildId: Snowflake, stickerId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildSticker(guildId, stickerId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1001,7 +1260,7 @@ export class GuildsAPI { public async createSticker( guildId: Snowflake, { file, ...body }: CreateStickerOptions, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { const fileData = { ...file, key: 'file' }; @@ -1011,6 +1270,9 @@ export class GuildsAPI { body, files: [fileData], reason, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1028,12 +1290,15 @@ export class GuildsAPI { guildId: Snowflake, stickerId: Snowflake, body: RESTPatchAPIGuildStickerJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guildSticker(guildId, stickerId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1049,9 +1314,16 @@ export class GuildsAPI { public async deleteSticker( guildId: Snowflake, stickerId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.guildSticker(guildId, stickerId), { auth, reason, signal }); + await this.rest.delete(Routes.guildSticker(guildId, stickerId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -1065,11 +1337,14 @@ export class GuildsAPI { public async getAuditLogs( guildId: Snowflake, query: RESTGetAPIAuditLogQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildAuditLog(guildId), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1081,9 +1356,15 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the auto moderation rules from * @param options - The options for fetching the auto moderation rules */ - public async getAutoModerationRules(guildId: Snowflake, { auth, signal }: Pick = {}) { + public async getAutoModerationRules( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.guildAutoModerationRules(guildId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1099,10 +1380,13 @@ export class GuildsAPI { public async getAutoModerationRule( guildId: Snowflake, ruleId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildAutoModerationRule(guildId, ruleId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1118,12 +1402,15 @@ export class GuildsAPI { public async createAutoModerationRule( guildId: Snowflake, body: RESTPostAPIAutoModerationRuleJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.guildAutoModerationRules(guildId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1141,12 +1428,15 @@ export class GuildsAPI { guildId: Snowflake, ruleId: Snowflake, body: RESTPatchAPIAutoModerationRuleJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guildAutoModerationRule(guildId, ruleId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1162,9 +1452,16 @@ export class GuildsAPI { public async deleteAutoModerationRule( guildId: Snowflake, ruleId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.guildAutoModerationRule(guildId, ruleId), { auth, reason, signal }); + await this.rest.delete(Routes.guildAutoModerationRule(guildId, ruleId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -1178,9 +1475,15 @@ export class GuildsAPI { public async getMember( guildId: Snowflake, userId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - return this.rest.get(Routes.guildMember(guildId, userId), { auth, signal }) as Promise; + return this.rest.get(Routes.guildMember(guildId, userId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -1194,11 +1497,14 @@ export class GuildsAPI { public async searchForMembers( guildId: Snowflake, query: RESTGetAPIGuildMembersSearchQuery, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildMembersSearch(guildId), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1214,11 +1520,14 @@ export class GuildsAPI { public async searchForMessages( guildId: Snowflake, query: RESTGetAPIGuildMessagesSearchQuery, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildMessagesSearch(guildId), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1236,12 +1545,15 @@ export class GuildsAPI { guildId: Snowflake, userId: Snowflake, body: RESTPatchAPIGuildMemberJSONBody = {}, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guildMember(guildId, userId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1257,9 +1569,16 @@ export class GuildsAPI { public async removeMember( guildId: Snowflake, userId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.guildMember(guildId, userId), { auth, reason, signal }); + await this.rest.delete(Routes.guildMember(guildId, userId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -1275,9 +1594,16 @@ export class GuildsAPI { guildId: Snowflake, userId: Snowflake, roleId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.put(Routes.guildMemberRole(guildId, userId, roleId), { auth, reason, signal }); + await this.rest.put(Routes.guildMemberRole(guildId, userId, roleId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -1293,9 +1619,16 @@ export class GuildsAPI { guildId: Snowflake, userId: Snowflake, roleId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.guildMemberRole(guildId, userId, roleId), { auth, reason, signal }); + await this.rest.delete(Routes.guildMemberRole(guildId, userId, roleId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -1305,8 +1638,17 @@ export class GuildsAPI { * @param templateCode - The code of the template * @param options - The options for fetching the guild template */ - public async getTemplate(templateCode: string, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.template(templateCode), { auth, signal }) as Promise; + public async getTemplate( + templateCode: string, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.template(templateCode), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -1320,11 +1662,14 @@ export class GuildsAPI { public async createTemplate( guildId: Snowflake, body: RESTPostAPIGuildTemplatesJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.post(Routes.guildTemplates(guildId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1336,8 +1681,17 @@ export class GuildsAPI { * @param id - The id of the guild * @param options - The options for fetching the webhooks */ - public async getWebhooks(id: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.guildWebhooks(id), { auth, signal }) as Promise; + public async getWebhooks( + id: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.guildWebhooks(id), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -1347,8 +1701,17 @@ export class GuildsAPI { * @param guildId - The id of the guild * @param options - The options for fetching the guild onboarding */ - public async getOnboarding(guildId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.guildOnboarding(guildId), { auth, signal }) as Promise; + public async getOnboarding( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.guildOnboarding(guildId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -1362,12 +1725,15 @@ export class GuildsAPI { public async editOnboarding( guildId: Snowflake, body: RESTPutAPIGuildOnboardingJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.put(Routes.guildOnboarding(guildId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1379,9 +1745,15 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch the soundboard sounds for * @param options - The options for fetching the soundboard sounds */ - public async getSoundboardSounds(guildId: Snowflake, { auth, signal }: Pick = {}) { + public async getSoundboardSounds( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.guildSoundboardSounds(guildId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1397,10 +1769,13 @@ export class GuildsAPI { public async getSoundboardSound( guildId: Snowflake, soundId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildSoundboardSound(guildId, soundId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1416,12 +1791,15 @@ export class GuildsAPI { public async createSoundboardSound( guildId: Snowflake, body: RESTPostAPIGuildSoundboardSoundJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.guildSoundboardSounds(guildId), { auth, body, reason, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1439,12 +1817,15 @@ export class GuildsAPI { guildId: Snowflake, soundId: Snowflake, body: RESTPatchAPIGuildSoundboardSoundJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guildSoundboardSound(guildId, soundId), { auth, body, reason, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1460,9 +1841,16 @@ export class GuildsAPI { public async deleteSoundboardSound( guildId: Snowflake, soundId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.guildSoundboardSound(guildId, soundId), { auth, reason, signal }); + await this.rest.delete(Routes.guildSoundboardSound(guildId, soundId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } /** @@ -1476,11 +1864,14 @@ export class GuildsAPI { public async editIncidentActions( guildId: Snowflake, body: RESTPutAPIGuildIncidentActionsJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.put(Routes.guildIncidentActions(guildId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -1492,9 +1883,15 @@ export class GuildsAPI { * @param guildId - The id of the guild to fetch role member counts for * @param options - The options for fetching role member counts */ - public async getRoleMemberCounts(guildId: Snowflake, { auth, signal }: Pick = {}) { + public async getRoleMemberCounts( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.guildRoleMemberCounts(guildId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } diff --git a/packages/core/src/api/interactions.ts b/packages/core/src/api/interactions.ts index 0be2439d1..45639a633 100644 --- a/packages/core/src/api/interactions.ts +++ b/packages/core/src/api/interactions.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import { makeURLSearchParams, type RawFile, type RequestData, type REST } from '@discordjs/rest'; +import { makeURLSearchParams, type RawFile, type REST } from '@discordjs/rest'; import { InteractionResponseType, Routes, @@ -13,6 +13,7 @@ import { type RESTPostAPIInteractionCallbackWithResponseResult, type Snowflake, } from 'discord-api-types/v10'; +import type { BaseRequestOptions } from '../util/types.js'; import type { WebhooksAPI } from './webhook.js'; export interface CreateInteractionResponseOptions @@ -53,7 +54,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, body: CreateInteractionResponseOptions & { with_response: true }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -69,7 +70,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, body: CreateInteractionResponseOptions & { with_response?: false }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -85,14 +86,14 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, body: CreateInteractionResponseOptions, - options?: Pick, + options?: BaseRequestOptions, ): Promise; public async reply( interactionId: Snowflake, interactionToken: string, { files, with_response, ...data }: CreateInteractionResponseOptions, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { query: makeURLSearchParams({ with_response }), @@ -102,6 +103,9 @@ export class InteractionsAPI { type: InteractionResponseType.ChannelMessageWithSource, data, }, + dispatcher, + headers, + rejectOnRateLimit, signal, }); @@ -121,7 +125,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, body: CreateInteractionDeferResponseOptions & { with_response: true }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -137,7 +141,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, body?: CreateInteractionDeferResponseOptions & { with_response?: false }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -153,14 +157,14 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, body?: CreateInteractionDeferResponseOptions, - options?: Pick, + options?: BaseRequestOptions, ): Promise; public async defer( interactionId: Snowflake, interactionToken: string, { with_response, ...data }: CreateInteractionDeferResponseOptions = {}, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { query: makeURLSearchParams({ with_response }), @@ -169,6 +173,9 @@ export class InteractionsAPI { type: InteractionResponseType.DeferredChannelMessageWithSource, data, }, + dispatcher, + headers, + rejectOnRateLimit, signal, }); @@ -188,7 +195,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, body: RESTPostAPIInteractionCallbackQuery & { with_response: true }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -204,7 +211,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, body?: RESTPostAPIInteractionCallbackQuery & { with_response?: false }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -220,14 +227,14 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, body?: RESTPostAPIInteractionCallbackQuery, - options?: Pick, + options?: BaseRequestOptions, ): Promise; public async deferMessageUpdate( interactionId: Snowflake, interactionToken: string, { with_response }: RESTPostAPIInteractionCallbackQuery = {}, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { query: makeURLSearchParams({ with_response }), @@ -235,6 +242,9 @@ export class InteractionsAPI { body: { type: InteractionResponseType.DeferredMessageUpdate, }, + dispatcher, + headers, + rejectOnRateLimit, signal, }); @@ -254,9 +264,14 @@ export class InteractionsAPI { applicationId: Snowflake, interactionToken: string, body: CreateInteractionFollowUpResponseOptions, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { - return this.webhooks.execute(applicationId, interactionToken, { ...body, wait: true }, { signal }); + return this.webhooks.execute( + applicationId, + interactionToken, + { ...body, wait: true }, + { dispatcher, headers, rejectOnRateLimit, signal }, + ); } /** @@ -275,9 +290,12 @@ export class InteractionsAPI { interactionToken: string, callbackData: EditInteractionResponseOptions, messageId?: Snowflake | '@original', - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { return this.webhooks.editMessage(applicationId, interactionToken, messageId ?? '@original', callbackData, { + dispatcher, + headers, + rejectOnRateLimit, signal, }); } @@ -293,14 +311,14 @@ export class InteractionsAPI { public async getOriginalReply( applicationId: Snowflake, interactionToken: string, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { return this.webhooks.getMessage( applicationId, interactionToken, '@original', {}, - { signal }, + { dispatcher, headers, rejectOnRateLimit, signal }, ) as Promise; } @@ -318,9 +336,15 @@ export class InteractionsAPI { applicationId: Snowflake, interactionToken: string, messageId?: Snowflake | '@original', - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { - await this.webhooks.deleteMessage(applicationId, interactionToken, messageId ?? '@original', {}, { signal }); + await this.webhooks.deleteMessage( + applicationId, + interactionToken, + messageId ?? '@original', + {}, + { dispatcher, headers, rejectOnRateLimit, signal }, + ); } /** @@ -336,7 +360,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, callbackData: CreateInteractionUpdateMessageResponseOptions & { with_response: true }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -352,7 +376,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, callbackData: CreateInteractionUpdateMessageResponseOptions & { with_response?: false }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -368,14 +392,14 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, callbackData: CreateInteractionUpdateMessageResponseOptions, - options?: Pick, + options?: BaseRequestOptions, ): Promise; public async updateMessage( interactionId: Snowflake, interactionToken: string, { files, with_response, ...data }: CreateInteractionUpdateMessageResponseOptions, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { query: makeURLSearchParams({ with_response }), @@ -385,6 +409,9 @@ export class InteractionsAPI { type: InteractionResponseType.UpdateMessage, data, }, + dispatcher, + headers, + rejectOnRateLimit, signal, }); @@ -404,7 +431,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, callbackData: CreateAutocompleteResponseOptions & { with_response: true }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -420,7 +447,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, callbackData: CreateAutocompleteResponseOptions & { with_response?: false }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -436,14 +463,14 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, callbackData: CreateAutocompleteResponseOptions, - options?: Pick, + options?: BaseRequestOptions, ): Promise; public async createAutocompleteResponse( interactionId: Snowflake, interactionToken: string, { with_response, ...data }: CreateAutocompleteResponseOptions, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { query: makeURLSearchParams({ with_response }), @@ -452,6 +479,9 @@ export class InteractionsAPI { type: InteractionResponseType.ApplicationCommandAutocompleteResult, data, }, + dispatcher, + headers, + rejectOnRateLimit, signal, }); @@ -471,7 +501,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, callbackData: CreateModalResponseOptions & { with_response: true }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -487,7 +517,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, callbackData: CreateModalResponseOptions & { with_response?: false }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -503,14 +533,14 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, callbackData: CreateModalResponseOptions, - options?: Pick, + options?: BaseRequestOptions, ): Promise; public async createModal( interactionId: Snowflake, interactionToken: string, { with_response, ...data }: CreateModalResponseOptions, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { query: makeURLSearchParams({ with_response }), @@ -519,6 +549,9 @@ export class InteractionsAPI { type: InteractionResponseType.Modal, data, }, + dispatcher, + headers, + rejectOnRateLimit, signal, }); @@ -538,7 +571,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, body: RESTPostAPIInteractionCallbackQuery & { with_response: true }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -554,7 +587,7 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, body?: RESTPostAPIInteractionCallbackQuery & { with_response?: false }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -570,14 +603,14 @@ export class InteractionsAPI { interactionId: Snowflake, interactionToken: string, body?: RESTPostAPIInteractionCallbackQuery, - options?: Pick, + options?: BaseRequestOptions, ): Promise; public async launchActivity( interactionId: Snowflake, interactionToken: string, { with_response }: RESTPostAPIInteractionCallbackQuery = {}, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { query: makeURLSearchParams({ with_response }), @@ -585,6 +618,9 @@ export class InteractionsAPI { body: { type: InteractionResponseType.LaunchActivity, }, + dispatcher, + headers, + rejectOnRateLimit, signal, }); diff --git a/packages/core/src/api/invite.ts b/packages/core/src/api/invite.ts index 9b9b97a67..a9bd62dfc 100644 --- a/packages/core/src/api/invite.ts +++ b/packages/core/src/api/invite.ts @@ -1,12 +1,13 @@ /* eslint-disable jsdoc/check-param-names */ -import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest'; +import { makeURLSearchParams, type REST } from '@discordjs/rest'; import { Routes, type RESTDeleteAPIInviteResult, type RESTGetAPIInviteQuery, type RESTGetAPIInviteResult, } from 'discord-api-types/v10'; +import type { RequestOptions, RequestOptionsWithReason } from '../util/types.js'; export class InvitesAPI { public constructor(private readonly rest: REST) {} @@ -22,11 +23,14 @@ export class InvitesAPI { public async get( code: string, query: RESTGetAPIInviteQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.invite(code), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -38,7 +42,17 @@ export class InvitesAPI { * @param code - The invite code * @param options - The options for deleting the invite */ - public async delete(code: string, { auth, reason, signal }: Pick = {}) { - return this.rest.delete(Routes.invite(code), { auth, reason, signal }) as Promise; + public async delete( + code: string, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, + ) { + return this.rest.delete(Routes.invite(code), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }) as Promise; } } diff --git a/packages/core/src/api/monetization.ts b/packages/core/src/api/monetization.ts index b06ff7eac..645b644fa 100644 --- a/packages/core/src/api/monetization.ts +++ b/packages/core/src/api/monetization.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest'; +import { makeURLSearchParams, type REST } from '@discordjs/rest'; import { Routes, type RESTGetAPIEntitlementsQuery, @@ -14,6 +14,7 @@ import { type RESTPostAPIEntitlementResult, type Snowflake, } from 'discord-api-types/v10'; +import type { RequestOptions } from '../util/types.js'; export class MonetizationAPI { public constructor(private readonly rest: REST) {} @@ -25,8 +26,17 @@ export class MonetizationAPI { * @param applicationId - The application id to fetch SKUs for * @param options - The options for fetching the SKUs. */ - public async getSKUs(applicationId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.skus(applicationId), { auth, signal }) as Promise; + public async getSKUs( + applicationId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.skus(applicationId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -40,10 +50,13 @@ export class MonetizationAPI { public async getSKUSubscriptions( skuId: Snowflake, query: RESTGetAPISKUSubscriptionsQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.skuSubscriptions(skuId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, query: makeURLSearchParams(query), }) as Promise; @@ -60,10 +73,13 @@ export class MonetizationAPI { public async getSKUSubscription( skuId: Snowflake, subscriptionId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.skuSubscription(skuId, subscriptionId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -79,10 +95,13 @@ export class MonetizationAPI { public async getEntitlements( applicationId: Snowflake, query: RESTGetAPIEntitlementsQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.entitlements(applicationId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, query: makeURLSearchParams(query), }) as Promise; @@ -99,10 +118,13 @@ export class MonetizationAPI { public async getEntitlement( applicationId: Snowflake, entitlementId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.entitlement(applicationId, entitlementId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -118,11 +140,14 @@ export class MonetizationAPI { public async createTestEntitlement( applicationId: Snowflake, body: RESTPostAPIEntitlementJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.post(Routes.entitlements(applicationId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -138,9 +163,15 @@ export class MonetizationAPI { public async deleteTestEntitlement( applicationId: Snowflake, entitlementId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - await this.rest.delete(Routes.entitlement(applicationId, entitlementId), { auth, signal }); + await this.rest.delete(Routes.entitlement(applicationId, entitlementId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }); } /** @@ -154,8 +185,14 @@ export class MonetizationAPI { public async consumeEntitlement( applicationId: Snowflake, entitlementId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - await this.rest.post(Routes.consumeEntitlement(applicationId, entitlementId), { auth, signal }); + await this.rest.post(Routes.consumeEntitlement(applicationId, entitlementId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }); } } diff --git a/packages/core/src/api/oauth2.ts b/packages/core/src/api/oauth2.ts index bf3d24916..6da5a0ff2 100644 --- a/packages/core/src/api/oauth2.ts +++ b/packages/core/src/api/oauth2.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import { type RequestData, type REST, makeURLSearchParams } from '@discordjs/rest'; +import { type REST, makeURLSearchParams } from '@discordjs/rest'; import { Routes, RouteBases, @@ -16,6 +16,7 @@ import { type RESTPostOAuth2TokenRevocationQuery, type Snowflake, } from 'discord-api-types/v10'; +import type { BaseRequestOptions, RequestOptions } from '../util/types.js'; export class OAuth2API { public constructor(private readonly rest: REST) {} @@ -41,15 +42,18 @@ export class OAuth2API { */ public async tokenExchange( body: RESTPostOAuth2AccessTokenURLEncodedData, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { return this.rest.post(Routes.oauth2TokenExchange(), { body: makeURLSearchParams(body), passThroughBody: true, headers: { + ...headers, 'Content-Type': 'application/x-www-form-urlencoded', }, auth: false, + dispatcher, + rejectOnRateLimit, signal, }) as Promise; } @@ -63,15 +67,18 @@ export class OAuth2API { */ public async refreshToken( body: RESTPostOAuth2RefreshTokenURLEncodedData, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { return this.rest.post(Routes.oauth2TokenExchange(), { body: makeURLSearchParams(body), passThroughBody: true, headers: { + ...headers, 'Content-Type': 'application/x-www-form-urlencoded', }, auth: false, + dispatcher, + rejectOnRateLimit, signal, }) as Promise; } @@ -87,15 +94,18 @@ export class OAuth2API { */ public async getToken( body: RESTPostOAuth2ClientCredentialsURLEncodedData, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { return this.rest.post(Routes.oauth2TokenExchange(), { body: makeURLSearchParams(body), passThroughBody: true, headers: { + ...headers, 'Content-Type': 'application/x-www-form-urlencoded', }, auth: false, + dispatcher, + rejectOnRateLimit, signal, }) as Promise; } @@ -106,9 +116,18 @@ export class OAuth2API { * @see {@link https://discord.com/developers/docs/topics/oauth2#get-current-bot-application-information} * @param options - The options for the current bot application information request */ - public async getCurrentBotApplicationInformation({ auth, signal }: Pick = {}) { + public async getCurrentBotApplicationInformation({ + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }: RequestOptions = {}) { return this.rest.get(Routes.oauth2CurrentApplication(), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -119,9 +138,18 @@ export class OAuth2API { * @see {@link https://discord.com/developers/docs/topics/oauth2#get-current-authorization-information} * @param options - The options for the current authorization information request */ - public async getCurrentAuthorizationInformation({ auth, signal }: Pick = {}) { + public async getCurrentAuthorizationInformation({ + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }: RequestOptions = {}) { return this.rest.get(Routes.oauth2CurrentAuthorization(), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -139,16 +167,19 @@ export class OAuth2API { applicationId: Snowflake, applicationSecret: string, body: RESTPostOAuth2TokenRevocationQuery, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { await this.rest.post(Routes.oauth2TokenRevocation(), { body: makeURLSearchParams(body), passThroughBody: true, headers: { + ...headers, Authorization: `Basic ${btoa(`${applicationId}:${applicationSecret}`)}`, 'Content-Type': 'application/x-www-form-urlencoded', }, auth: false, + dispatcher, + rejectOnRateLimit, signal, }); } diff --git a/packages/core/src/api/poll.ts b/packages/core/src/api/poll.ts index a041efdd8..cd2f602ef 100644 --- a/packages/core/src/api/poll.ts +++ b/packages/core/src/api/poll.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest'; +import { makeURLSearchParams, type REST } from '@discordjs/rest'; import { Routes, type RESTGetAPIPollAnswerVotersQuery, @@ -8,6 +8,7 @@ import { type RESTPostAPIPollExpireResult, type Snowflake, } from 'discord-api-types/v10'; +import type { RequestOptions } from '../util/types.js'; export class PollAPI { public constructor(private readonly rest: REST) {} @@ -27,10 +28,13 @@ export class PollAPI { messageId: Snowflake, answerId: number, query: RESTGetAPIPollAnswerVotersQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.pollAnswerVoters(channelId, messageId, answerId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, query: makeURLSearchParams(query), }) as Promise; @@ -47,10 +51,13 @@ export class PollAPI { public async expirePoll( channelId: Snowflake, messageId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.post(Routes.expirePoll(channelId, messageId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } diff --git a/packages/core/src/api/roleConnections.ts b/packages/core/src/api/roleConnections.ts index 1ea9a1c99..25289b45e 100644 --- a/packages/core/src/api/roleConnections.ts +++ b/packages/core/src/api/roleConnections.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import type { RequestData, REST } from '@discordjs/rest'; +import type { REST } from '@discordjs/rest'; import { Routes, type RESTGetAPIApplicationRoleConnectionMetadataResult, @@ -8,6 +8,7 @@ import { type RESTPutAPIApplicationRoleConnectionMetadataJSONBody, type Snowflake, } from 'discord-api-types/v10'; +import type { RequestOptions } from '../util/types.js'; export class RoleConnectionsAPI { public constructor(private readonly rest: REST) {} @@ -21,10 +22,13 @@ export class RoleConnectionsAPI { */ public async getMetadataRecords( applicationId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.applicationRoleConnectionMetadata(applicationId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -40,11 +44,14 @@ export class RoleConnectionsAPI { public async updateMetadataRecords( applicationId: Snowflake, body: RESTPutAPIApplicationRoleConnectionMetadataJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.put(Routes.applicationRoleConnectionMetadata(applicationId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } diff --git a/packages/core/src/api/soundboardSounds.ts b/packages/core/src/api/soundboardSounds.ts index 0e44adcb0..d26005025 100644 --- a/packages/core/src/api/soundboardSounds.ts +++ b/packages/core/src/api/soundboardSounds.ts @@ -1,7 +1,8 @@ /* eslint-disable jsdoc/check-param-names */ -import type { RequestData, REST } from '@discordjs/rest'; +import type { REST } from '@discordjs/rest'; import { Routes, type RESTGetAPISoundboardDefaultSoundsResult } from 'discord-api-types/v10'; +import type { RequestOptions } from '../util/types.js'; export class SoundboardSoundsAPI { public constructor(private readonly rest: REST) {} @@ -12,9 +13,18 @@ export class SoundboardSoundsAPI { * @see {@link https://discord.com/developers/docs/resources/soundboard#list-default-soundboard-sounds} * @param options - The options for fetching the soundboard default sounds. */ - public async getSoundboardDefaultSounds({ auth, signal }: Pick = {}) { + public async getSoundboardDefaultSounds({ + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }: RequestOptions = {}) { return this.rest.get(Routes.soundboardDefaultSounds(), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } diff --git a/packages/core/src/api/stageInstances.ts b/packages/core/src/api/stageInstances.ts index 5a0cd0274..72e42f085 100644 --- a/packages/core/src/api/stageInstances.ts +++ b/packages/core/src/api/stageInstances.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import type { RequestData, REST } from '@discordjs/rest'; +import type { REST } from '@discordjs/rest'; import { type Snowflake, type RESTGetAPIStageInstanceResult, @@ -10,6 +10,7 @@ import { type RESTPostAPIStageInstanceResult, Routes, } from 'discord-api-types/v10'; +import type { RequestOptions, RequestOptionsWithReason } from '../util/types.js'; export class StageInstancesAPI { public constructor(private readonly rest: REST) {} @@ -23,12 +24,15 @@ export class StageInstancesAPI { */ public async create( body: RESTPostAPIStageInstanceJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.post(Routes.stageInstances(), { auth, body, reason, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -40,8 +44,17 @@ export class StageInstancesAPI { * @param channelId - The id of the channel * @param options - The options for fetching the stage instance */ - public async get(channelId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.stageInstance(channelId), { auth, signal }) as Promise; + public async get( + channelId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.stageInstance(channelId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -55,12 +68,15 @@ export class StageInstancesAPI { public async edit( channelId: Snowflake, body: RESTPatchAPIStageInstanceJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.stageInstance(channelId), { auth, body, reason, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -74,8 +90,15 @@ export class StageInstancesAPI { */ public async delete( channelId: Snowflake, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { - await this.rest.delete(Routes.stageInstance(channelId), { auth, reason, signal }); + await this.rest.delete(Routes.stageInstance(channelId), { + auth, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }); } } diff --git a/packages/core/src/api/sticker.ts b/packages/core/src/api/sticker.ts index 76c832d6a..e855becfb 100644 --- a/packages/core/src/api/sticker.ts +++ b/packages/core/src/api/sticker.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import type { RequestData, REST } from '@discordjs/rest'; +import type { REST } from '@discordjs/rest'; import { Routes, type RESTGetAPIStickerPackResult, @@ -8,6 +8,7 @@ import { type RESTGetStickerPacksResult, type Snowflake, } from 'discord-api-types/v10'; +import type { RequestOptions } from '../util/types.js'; export class StickersAPI { public constructor(private readonly rest: REST) {} @@ -19,8 +20,17 @@ export class StickersAPI { * @param packId - The id of the sticker pack * @param options - The options for fetching the sticker pack */ - public async getStickerPack(packId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.stickerPack(packId), { auth, signal }) as Promise; + public async getStickerPack( + packId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.stickerPack(packId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -29,8 +39,14 @@ export class StickersAPI { * @see {@link https://discord.com/developers/docs/resources/sticker#list-sticker-packs} * @param options - The options for fetching the sticker packs */ - public async getStickers({ auth, signal }: Pick = {}) { - return this.rest.get(Routes.stickerPacks(), { auth, signal }) as Promise; + public async getStickers({ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) { + return this.rest.get(Routes.stickerPacks(), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -40,7 +56,16 @@ export class StickersAPI { * @param stickerId - The id of the sticker * @param options - The options for fetching the sticker */ - public async get(stickerId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.sticker(stickerId), { auth, signal }) as Promise; + public async get( + stickerId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + return this.rest.get(Routes.sticker(stickerId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } } diff --git a/packages/core/src/api/thread.ts b/packages/core/src/api/thread.ts index dd8f97e12..8b01b2917 100644 --- a/packages/core/src/api/thread.ts +++ b/packages/core/src/api/thread.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest'; +import { makeURLSearchParams, type REST } from '@discordjs/rest'; import { Routes, type RESTGetAPIChannelThreadMemberQuery, @@ -9,6 +9,7 @@ import { type RESTGetAPIChannelThreadMembersResult, type Snowflake, } from 'discord-api-types/v10'; +import type { RequestOptions } from '../util/types.js'; export class ThreadsAPI { public constructor(private readonly rest: REST) {} @@ -20,8 +21,17 @@ export class ThreadsAPI { * @param threadId - The id of the thread to join * @param options - The options for joining the thread */ - public async join(threadId: Snowflake, { auth, signal }: Pick = {}) { - await this.rest.put(Routes.threadMembers(threadId, '@me'), { auth, signal }); + public async join( + threadId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + await this.rest.put(Routes.threadMembers(threadId, '@me'), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }); } /** @@ -35,9 +45,15 @@ export class ThreadsAPI { public async addMember( threadId: Snowflake, userId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - await this.rest.put(Routes.threadMembers(threadId, userId), { auth, signal }); + await this.rest.put(Routes.threadMembers(threadId, userId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }); } /** @@ -47,8 +63,17 @@ export class ThreadsAPI { * @param threadId - The id of the thread to leave * @param options - The options for leaving the thread */ - public async leave(threadId: Snowflake, { auth, signal }: Pick = {}) { - await this.rest.delete(Routes.threadMembers(threadId, '@me'), { auth, signal }); + public async leave( + threadId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + await this.rest.delete(Routes.threadMembers(threadId, '@me'), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }); } /** @@ -62,9 +87,15 @@ export class ThreadsAPI { public async removeMember( threadId: Snowflake, userId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - await this.rest.delete(Routes.threadMembers(threadId, userId), { auth, signal }); + await this.rest.delete(Routes.threadMembers(threadId, userId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }); } /** @@ -80,7 +111,7 @@ export class ThreadsAPI { threadId: Snowflake, userId: Snowflake, query: RESTGetAPIChannelThreadMemberQuery & { with_member: true }, - options?: Pick, + options?: RequestOptions, ): Promise> & RESTGetAPIChannelThreadMemberResult>; /** @@ -96,17 +127,20 @@ export class ThreadsAPI { threadId: Snowflake, userId: Snowflake, query?: RESTGetAPIChannelThreadMemberQuery, - options?: Pick, + options?: RequestOptions, ): Promise; public async getMember( threadId: Snowflake, userId: Snowflake, query: RESTGetAPIChannelThreadMemberQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.threadMembers(threadId, userId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, query: makeURLSearchParams(query), }); @@ -123,10 +157,13 @@ export class ThreadsAPI { public async getMembers( threadId: Snowflake, query: RESTGetAPIChannelThreadMembersQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.threadMembers(threadId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, query: makeURLSearchParams(query), }) as Promise; diff --git a/packages/core/src/api/user.ts b/packages/core/src/api/user.ts index c355d1585..29eb3400b 100644 --- a/packages/core/src/api/user.ts +++ b/packages/core/src/api/user.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest'; +import { makeURLSearchParams, type REST } from '@discordjs/rest'; import { Routes, type RESTGetAPICurrentUserApplicationRoleConnectionResult, @@ -19,6 +19,7 @@ import { type RESTPutAPICurrentUserApplicationRoleConnectionResult, type Snowflake, } from 'discord-api-types/v10'; +import type { RequestOptions, RequestOptionsWithReason } from '../util/types.js'; export class UsersAPI { public constructor(private readonly rest: REST) {} @@ -30,8 +31,14 @@ export class UsersAPI { * @param userId - The id of the user to fetch * @param options - The options for fetching the user */ - public async get(userId: Snowflake, { auth, signal }: Pick = {}) { - return this.rest.get(Routes.user(userId), { auth, signal }) as Promise; + public async get(userId: Snowflake, { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) { + return this.rest.get(Routes.user(userId), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -40,8 +47,14 @@ export class UsersAPI { * @see {@link https://discord.com/developers/docs/resources/user#get-current-user} * @param options - The options for fetching the current user */ - public async getCurrent({ auth, signal }: Pick = {}) { - return this.rest.get(Routes.user('@me'), { auth, signal }) as Promise; + public async getCurrent({ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) { + return this.rest.get(Routes.user('@me'), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -53,11 +66,14 @@ export class UsersAPI { */ public async getGuilds( query: RESTGetAPICurrentUserGuildsQuery = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.userGuilds(), { auth, query: makeURLSearchParams(query), + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -69,8 +85,11 @@ export class UsersAPI { * @param guildId - The id of the guild * @param options - The options for leaving the guild */ - public async leaveGuild(guildId: Snowflake, { auth, signal }: Pick = {}) { - await this.rest.delete(Routes.userGuild(guildId), { auth, signal }); + public async leaveGuild( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { + await this.rest.delete(Routes.userGuild(guildId), { auth, dispatcher, headers, rejectOnRateLimit, signal }); } /** @@ -82,9 +101,16 @@ export class UsersAPI { */ public async edit( body: RESTPatchAPICurrentUserJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { - return this.rest.patch(Routes.user('@me'), { auth, body, signal }) as Promise; + return this.rest.patch(Routes.user('@me'), { + auth, + body, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -94,9 +120,15 @@ export class UsersAPI { * @param guildId - The id of the guild * @param options - The options for fetching the guild member */ - public async getGuildMember(guildId: Snowflake, { auth, signal }: Pick = {}) { + public async getGuildMember( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.userGuildMember(guildId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -112,12 +144,15 @@ export class UsersAPI { public async editCurrentGuildMember( guildId: Snowflake, body: RESTPatchAPICurrentGuildMemberJSONBody = {}, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guildMember(guildId, '@me'), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -129,10 +164,16 @@ export class UsersAPI { * @param userId - The id of the user to open a DM channel with * @param options - The options for opening the DM */ - public async createDM(userId: Snowflake, { auth, signal }: Pick = {}) { + public async createDM( + userId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.post(Routes.userChannels(), { auth, body: { recipient_id: userId }, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -143,8 +184,14 @@ export class UsersAPI { * @see {@link https://discord.com/developers/docs/resources/user#get-user-connections} * @param options - The options for fetching the user's connections */ - public async getConnections({ auth, signal }: Pick = {}) { - return this.rest.get(Routes.userConnections(), { auth, signal }) as Promise; + public async getConnections({ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) { + return this.rest.get(Routes.userConnections(), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -156,10 +203,13 @@ export class UsersAPI { */ public async getApplicationRoleConnection( applicationId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.userApplicationRoleConnection(applicationId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -175,11 +225,14 @@ export class UsersAPI { public async updateApplicationRoleConnection( applicationId: Snowflake, body: RESTPutAPICurrentUserApplicationRoleConnectionJSONBody, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.put(Routes.userApplicationRoleConnection(applicationId), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -193,10 +246,13 @@ export class UsersAPI { */ public async deleteApplicationRoleConnection( applicationId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { await this.rest.delete(Routes.userApplicationRoleConnection(applicationId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }); } diff --git a/packages/core/src/api/voice.ts b/packages/core/src/api/voice.ts index aca94243b..2b7dd4d10 100644 --- a/packages/core/src/api/voice.ts +++ b/packages/core/src/api/voice.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import type { RequestData, REST } from '@discordjs/rest'; +import type { REST } from '@discordjs/rest'; import { Routes, type Snowflake, @@ -12,6 +12,7 @@ import { type RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody, type RESTPatchAPIGuildVoiceStateUserResult, } from 'discord-api-types/v10'; +import type { RequestOptions, RequestOptionsWithReason } from '../util/types.js'; export class VoiceAPI { public constructor(private readonly rest: REST) {} @@ -22,8 +23,14 @@ export class VoiceAPI { * @see {@link https://discord.com/developers/docs/resources/voice#list-voice-regions} * @param options - The options for fetching the voice regions */ - public async getVoiceRegions({ auth, signal }: Pick = {}) { - return this.rest.get(Routes.voiceRegions(), { auth, signal }) as Promise; + public async getVoiceRegions({ auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}) { + return this.rest.get(Routes.voiceRegions(), { + auth, + dispatcher, + headers, + rejectOnRateLimit, + signal, + }) as Promise; } /** @@ -35,10 +42,13 @@ export class VoiceAPI { public async getUserVoiceState( guildId: Snowflake, userId: Snowflake, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.get(Routes.guildVoiceState(guildId, userId), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -49,9 +59,15 @@ export class VoiceAPI { * @see {@link https://discord.com/developers/docs/resources/voice#get-current-user-voice-state} * @param options - The options for fetching user voice state */ - public async getVoiceState(guildId: Snowflake, { auth, signal }: Pick = {}) { + public async getVoiceState( + guildId: Snowflake, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, + ) { return this.rest.get(Routes.guildVoiceState(guildId, '@me'), { auth, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -69,12 +85,15 @@ export class VoiceAPI { guildId: Snowflake, userId: Snowflake, body: RESTPatchAPIGuildVoiceStateUserJSONBody, - { auth, reason, signal }: Pick = {}, + { auth, dispatcher, headers, reason, rejectOnRateLimit, signal }: RequestOptionsWithReason = {}, ) { return this.rest.patch(Routes.guildVoiceState(guildId, userId), { auth, reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -90,11 +109,14 @@ export class VoiceAPI { public async editVoiceState( guildId: Snowflake, body: RESTPatchAPIGuildVoiceStateCurrentMemberJSONBody = {}, - { auth, signal }: Pick = {}, + { auth, dispatcher, headers, rejectOnRateLimit, signal }: RequestOptions = {}, ) { return this.rest.patch(Routes.guildVoiceState(guildId, '@me'), { auth, body, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } diff --git a/packages/core/src/api/webhook.ts b/packages/core/src/api/webhook.ts index e0557c1db..55ae13054 100644 --- a/packages/core/src/api/webhook.ts +++ b/packages/core/src/api/webhook.ts @@ -1,6 +1,6 @@ /* eslint-disable jsdoc/check-param-names */ -import { makeURLSearchParams, type RequestData, type RawFile, type REST } from '@discordjs/rest'; +import { makeURLSearchParams, type RawFile, type REST } from '@discordjs/rest'; import { Routes, type RESTGetAPIWebhookWithTokenMessageQuery, @@ -19,6 +19,7 @@ import { type RESTDeleteAPIWebhookWithTokenMessageQuery, type Snowflake, } from 'discord-api-types/v10'; +import type { BaseRequestOptions, BaseRequestOptionsWithReason } from '../util/types.js'; export type CreateWebhookMessageOptions = RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[] }; @@ -41,9 +42,12 @@ export class WebhooksAPI { */ public async get( id: Snowflake, - { token, signal }: Pick & { token?: string | undefined } = {}, + { token, dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions & { token?: string | undefined } = {}, ) { return this.rest.get(Routes.webhook(id, token), { + dispatcher, + headers, + rejectOnRateLimit, signal, auth: !token, }) as Promise; @@ -61,11 +65,21 @@ export class WebhooksAPI { public async edit( id: Snowflake, body: RESTPatchAPIWebhookJSONBody, - { token, reason, signal }: Pick & { token?: string | undefined } = {}, + { + token, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }: BaseRequestOptionsWithReason & { token?: string | undefined } = {}, ) { return this.rest.patch(Routes.webhook(id, token), { reason, body, + dispatcher, + headers, + rejectOnRateLimit, signal, auth: !token, }) as Promise; @@ -81,10 +95,20 @@ export class WebhooksAPI { */ public async delete( id: Snowflake, - { token, reason, signal }: Pick & { token?: string | undefined } = {}, + { + token, + dispatcher, + headers, + reason, + rejectOnRateLimit, + signal, + }: BaseRequestOptionsWithReason & { token?: string | undefined } = {}, ) { await this.rest.delete(Routes.webhook(id, token), { reason, + dispatcher, + headers, + rejectOnRateLimit, signal, auth: !token, }); @@ -103,7 +127,7 @@ export class WebhooksAPI { id: Snowflake, token: string, body: CreateWebhookMessageOptions & { wait: true }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -119,7 +143,7 @@ export class WebhooksAPI { id: Snowflake, token: string, body: CreateWebhookMessageOptions & { wait?: false }, - options?: Pick, + options?: BaseRequestOptions, ): Promise; /** @@ -135,13 +159,16 @@ export class WebhooksAPI { id: Snowflake, token: string, { wait, thread_id, with_components, files, ...body }: CreateWebhookMessageOptions, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { return this.rest.post(Routes.webhook(id, token), { query: makeURLSearchParams({ wait, thread_id, with_components }), files, body, auth: false, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -161,12 +188,15 @@ export class WebhooksAPI { token: string, body: unknown, query: RESTPostAPIWebhookWithTokenSlackQuery = {}, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { await this.rest.post(Routes.webhookPlatform(id, token, 'slack'), { query: makeURLSearchParams(query), body, auth: false, + dispatcher, + headers, + rejectOnRateLimit, signal, }); } @@ -186,11 +216,14 @@ export class WebhooksAPI { token: string, body: unknown, query: RESTPostAPIWebhookWithTokenGitHubQuery = {}, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { await this.rest.post(Routes.webhookPlatform(id, token, 'github'), { query: makeURLSearchParams(query), body, + dispatcher, + headers, + rejectOnRateLimit, signal, auth: false, }); @@ -211,11 +244,14 @@ export class WebhooksAPI { token: string, messageId: Snowflake, query: RESTGetAPIWebhookWithTokenMessageQuery = {}, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { return this.rest.get(Routes.webhookMessage(id, token, messageId), { query: makeURLSearchParams(query), auth: false, + dispatcher, + headers, + rejectOnRateLimit, signal, }) as Promise; } @@ -235,12 +271,15 @@ export class WebhooksAPI { token: string, messageId: Snowflake, { thread_id, with_components, files, ...body }: EditWebhookMessageOptions, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { return this.rest.patch(Routes.webhookMessage(id, token, messageId), { query: makeURLSearchParams({ thread_id, with_components }), auth: false, body, + dispatcher, + headers, + rejectOnRateLimit, signal, files, }) as Promise; @@ -261,11 +300,14 @@ export class WebhooksAPI { token: string, messageId: Snowflake, query: RESTDeleteAPIWebhookWithTokenMessageQuery = {}, - { signal }: Pick = {}, + { dispatcher, headers, rejectOnRateLimit, signal }: BaseRequestOptions = {}, ) { await this.rest.delete(Routes.webhookMessage(id, token, messageId), { query: makeURLSearchParams(query), auth: false, + dispatcher, + headers, + rejectOnRateLimit, signal, }); } diff --git a/packages/core/src/util/index.ts b/packages/core/src/util/index.ts index f2891a7c9..935b4fc02 100644 --- a/packages/core/src/util/index.ts +++ b/packages/core/src/util/index.ts @@ -1 +1,2 @@ export * from './files.js'; +export type * from './types.js'; diff --git a/packages/core/src/util/types.ts b/packages/core/src/util/types.ts new file mode 100644 index 000000000..0acd6d476 --- /dev/null +++ b/packages/core/src/util/types.ts @@ -0,0 +1,21 @@ +import type { RequestData } from '@discordjs/rest'; + +/** + * Per-request options accepted by API methods that do not take alternate authorization + */ +export type BaseRequestOptions = Pick; + +/** + * Per-request options accepted by API methods that take an audit log reason but no alternate authorization + */ +export type BaseRequestOptionsWithReason = BaseRequestOptions & Pick; + +/** + * Per-request options accepted by API methods + */ +export type RequestOptions = BaseRequestOptions & Pick; + +/** + * Per-request options accepted by API methods that take an audit log reason + */ +export type RequestOptionsWithReason = Pick & RequestOptions; diff --git a/packages/rest/src/lib/utils/types.ts b/packages/rest/src/lib/utils/types.ts index 401c9a493..64f0b1362 100644 --- a/packages/rest/src/lib/utils/types.ts +++ b/packages/rest/src/lib/utils/types.ts @@ -321,7 +321,7 @@ export interface RequestData { /** * The {@link https://undici.nodejs.org/#/docs/api/Agent | Agent} to use for the request. */ - dispatcher?: Agent; + dispatcher?: Agent | undefined; /** * Files to be attached to this request */ @@ -329,7 +329,7 @@ export interface RequestData { /** * Additional headers to add to this request */ - headers?: Record; + headers?: Record | undefined; /** * Whether to pass-through the body property directly to `fetch()`. * This only applies when files is NOT present