diff --git a/packages/core/src/api/channel.ts b/packages/core/src/api/channel.ts index 302ff5086..a89a06c75 100644 --- a/packages/core/src/api/channel.ts +++ b/packages/core/src/api/channel.ts @@ -42,6 +42,14 @@ export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSO message: RESTPostAPIGuildForumThreadsJSONBody['message'] & { files?: RawFile[] }; } +export interface CreateMessageOptions extends RESTPostAPIChannelMessageJSONBody { + files?: RawFile[]; +} + +export interface EditMessageOptions extends RESTPatchAPIChannelMessageJSONBody { + files?: RawFile[]; +} + export class ChannelsAPI { public constructor(private readonly rest: REST) {} @@ -55,7 +63,7 @@ export class ChannelsAPI { */ public async createMessage( channelId: Snowflake, - { files, ...body }: RESTPostAPIChannelMessageJSONBody & { files?: RawFile[] }, + { files, ...body }: CreateMessageOptions, { signal }: Pick = {}, ) { return this.rest.post(Routes.channelMessages(channelId), { @@ -77,7 +85,7 @@ export class ChannelsAPI { public async editMessage( channelId: Snowflake, messageId: Snowflake, - { files, ...body }: RESTPatchAPIChannelMessageJSONBody & { files?: RawFile[] }, + { files, ...body }: EditMessageOptions, { signal }: Pick = {}, ) { return this.rest.patch(Routes.channelMessage(channelId, messageId), { diff --git a/packages/core/src/api/guild.ts b/packages/core/src/api/guild.ts index f09f51c91..5e003096f 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 RawFile, type REST, type RequestData } from '@discordjs/rest'; import { Routes, type GuildMFALevel, @@ -112,6 +112,10 @@ import { } from 'discord-api-types/v10'; import { VoiceAPI } from './voice'; +export interface CreateStickerOptions extends Omit { + file: RawFile; +} + export class GuildsAPI { public constructor(private readonly rest: REST) {} @@ -1018,7 +1022,7 @@ export class GuildsAPI { */ public async createSticker( guildId: Snowflake, - { file, ...body }: Omit & { file: RawFile }, + { file, ...body }: CreateStickerOptions, { reason, signal }: Pick = {}, ) { const fileData = { ...file, key: 'file' }; diff --git a/packages/core/src/api/interactions.ts b/packages/core/src/api/interactions.ts index 2ebe5f668..2b680dd10 100644 --- a/packages/core/src/api/interactions.ts +++ b/packages/core/src/api/interactions.ts @@ -16,6 +16,26 @@ import { } from 'discord-api-types/v10'; import type { WebhooksAPI } from './webhook.js'; +export interface CreateInteractionResponseOptions + extends APIInteractionResponseCallbackData, + RESTPostAPIInteractionCallbackQuery { + files?: RawFile[]; +} + +export type CreateInteractionDeferResponseOptions = APIInteractionResponseDeferredChannelMessageWithSource['data'] & + RESTPostAPIInteractionCallbackQuery; + +export type CreateInteractionFollowUpResponseOptions = APIInteractionResponseCallbackData & { files?: RawFile[] }; +export type EditInteractionResponseOptions = APIInteractionResponseCallbackData & { files?: RawFile[] }; + +export type CreateInteractionUpdateMessageResponseOptions = APIInteractionResponseCallbackData & + RESTPostAPIInteractionCallbackQuery & { files?: RawFile[] }; + +export type CreateAutocompleteResponseOptions = APICommandAutocompleteInteractionResponseCallbackData & + RESTPostAPIInteractionCallbackQuery; + +export type CreateModalResponseOptions = APIModalInteractionResponseCallbackData & RESTPostAPIInteractionCallbackQuery; + export class InteractionsAPI { public constructor( private readonly rest: REST, @@ -34,8 +54,7 @@ export class InteractionsAPI { public async reply( interactionId: Snowflake, interactionToken: string, - body: APIInteractionResponseCallbackData & - RESTPostAPIInteractionCallbackQuery & { files?: RawFile[]; with_response: true }, + body: CreateInteractionResponseOptions & { with_response: true }, options?: Pick, ): Promise; @@ -51,19 +70,14 @@ export class InteractionsAPI { public async reply( interactionId: Snowflake, interactionToken: string, - body: APIInteractionResponseCallbackData & - RESTPostAPIInteractionCallbackQuery & { files?: RawFile[]; with_response?: false }, + body: CreateInteractionResponseOptions & { with_response?: false }, options?: Pick, ): Promise; public async reply( interactionId: Snowflake, interactionToken: string, - { - files, - with_response, - ...data - }: APIInteractionResponseCallbackData & RESTPostAPIInteractionCallbackQuery & { files?: RawFile[] }, + { files, with_response, ...data }: CreateInteractionResponseOptions, { signal }: Pick = {}, ) { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { @@ -92,8 +106,7 @@ export class InteractionsAPI { public async defer( interactionId: Snowflake, interactionToken: string, - body: APIInteractionResponseDeferredChannelMessageWithSource['data'] & - RESTPostAPIInteractionCallbackQuery & { with_response: true }, + body: CreateInteractionDeferResponseOptions & { with_response: true }, options?: Pick, ): Promise; @@ -109,18 +122,14 @@ export class InteractionsAPI { public async defer( interactionId: Snowflake, interactionToken: string, - body?: APIInteractionResponseDeferredChannelMessageWithSource['data'] & - RESTPostAPIInteractionCallbackQuery & { with_response?: false }, + body?: CreateInteractionDeferResponseOptions & { with_response?: false }, options?: Pick, ): Promise; public async defer( interactionId: Snowflake, interactionToken: string, - { - with_response, - ...data - }: APIInteractionResponseDeferredChannelMessageWithSource['data'] & RESTPostAPIInteractionCallbackQuery = {}, + { with_response, ...data }: CreateInteractionDeferResponseOptions = {}, { signal }: Pick = {}, ) { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { @@ -198,7 +207,7 @@ export class InteractionsAPI { public async followUp( applicationId: Snowflake, interactionToken: string, - body: APIInteractionResponseCallbackData & { files?: RawFile[] }, + body: CreateInteractionFollowUpResponseOptions, { signal }: Pick = {}, ) { return this.webhooks.execute(applicationId, interactionToken, { ...body, wait: true }, { signal }); @@ -218,7 +227,7 @@ export class InteractionsAPI { public async editReply( applicationId: Snowflake, interactionToken: string, - callbackData: APIInteractionResponseCallbackData & { files?: RawFile[] }, + callbackData: EditInteractionResponseOptions, messageId?: Snowflake | '@original', { signal }: Pick = {}, ) { @@ -280,8 +289,7 @@ export class InteractionsAPI { public async updateMessage( interactionId: Snowflake, interactionToken: string, - callbackData: APIInteractionResponseCallbackData & - RESTPostAPIInteractionCallbackQuery & { files?: RawFile[]; with_response: true }, + callbackData: CreateInteractionUpdateMessageResponseOptions & { with_response: true }, options: Pick, ): Promise; @@ -297,19 +305,14 @@ export class InteractionsAPI { public async updateMessage( interactionId: Snowflake, interactionToken: string, - callbackData: APIInteractionResponseCallbackData & - RESTPostAPIInteractionCallbackQuery & { files?: RawFile[]; with_response?: false }, + callbackData: CreateInteractionUpdateMessageResponseOptions & { with_response?: false }, options: Pick, ): Promise; public async updateMessage( interactionId: Snowflake, interactionToken: string, - { - files, - with_response, - ...data - }: APIInteractionResponseCallbackData & RESTPostAPIInteractionCallbackQuery & { files?: RawFile[] }, + { files, with_response, ...data }: CreateInteractionUpdateMessageResponseOptions, { signal }: Pick = {}, ) { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { @@ -338,8 +341,7 @@ export class InteractionsAPI { public async createAutocompleteResponse( interactionId: Snowflake, interactionToken: string, - callbackData: APICommandAutocompleteInteractionResponseCallbackData & - RESTPostAPIInteractionCallbackQuery & { with_response: true }, + callbackData: CreateAutocompleteResponseOptions & { with_response: true }, options?: Pick, ): Promise; @@ -355,18 +357,14 @@ export class InteractionsAPI { public async createAutocompleteResponse( interactionId: Snowflake, interactionToken: string, - callbackData: APICommandAutocompleteInteractionResponseCallbackData & - RESTPostAPIInteractionCallbackQuery & { with_response?: false }, + callbackData: CreateAutocompleteResponseOptions & { with_response?: false }, options: Pick, ): Promise; public async createAutocompleteResponse( interactionId: Snowflake, interactionToken: string, - { - with_response, - ...data - }: APICommandAutocompleteInteractionResponseCallbackData & RESTPostAPIInteractionCallbackQuery, + { with_response, ...data }: CreateAutocompleteResponseOptions, { signal }: Pick = {}, ) { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { @@ -394,8 +392,7 @@ export class InteractionsAPI { public async createModal( interactionId: Snowflake, interactionToken: string, - callbackData: APIModalInteractionResponseCallbackData & - RESTPostAPIInteractionCallbackQuery & { with_response: true }, + callbackData: CreateModalResponseOptions & { with_response: true }, options?: Pick, ): Promise; @@ -411,15 +408,14 @@ export class InteractionsAPI { public async createModal( interactionId: Snowflake, interactionToken: string, - callbackData: APIModalInteractionResponseCallbackData & - RESTPostAPIInteractionCallbackQuery & { with_response?: false }, + callbackData: CreateModalResponseOptions & { with_response?: false }, options?: Pick, ): Promise; public async createModal( interactionId: Snowflake, interactionToken: string, - { with_response, ...data }: APIModalInteractionResponseCallbackData & RESTPostAPIInteractionCallbackQuery, + { with_response, ...data }: CreateModalResponseOptions, { signal }: Pick = {}, ) { const response = await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { diff --git a/packages/core/src/api/webhook.ts b/packages/core/src/api/webhook.ts index 38dc91412..d26d0c70e 100644 --- a/packages/core/src/api/webhook.ts +++ b/packages/core/src/api/webhook.ts @@ -19,6 +19,14 @@ import { type Snowflake, } from 'discord-api-types/v10'; +export type CreateWebhookMessageOptions = RESTPostAPIWebhookWithTokenJSONBody & + RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[] }; + +export type EditWebhookMessageOptions = RESTPatchAPIWebhookWithTokenMessageJSONBody & RESTPatchAPIWebhookWithTokenMessageQuery & { + files?: RawFile[]; + thread_id?: string; +}; + export class WebhooksAPI { public constructor(private readonly rest: REST) {} @@ -93,7 +101,7 @@ export class WebhooksAPI { public async execute( id: Snowflake, token: string, - body: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[]; wait: true }, + body: CreateWebhookMessageOptions & { wait: true }, options?: Pick, ): Promise; @@ -109,7 +117,7 @@ export class WebhooksAPI { public async execute( id: Snowflake, token: string, - body: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[]; wait?: false }, + body: CreateWebhookMessageOptions & { wait?: false }, options?: Pick, ): Promise; @@ -125,13 +133,7 @@ export class WebhooksAPI { public async execute( id: Snowflake, token: string, - { - wait, - thread_id, - with_components, - files, - ...body - }: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[] }, + { wait, thread_id, with_components, files, ...body }: CreateWebhookMessageOptions, { signal }: Pick = {}, ) { return this.rest.post(Routes.webhook(id, token), { @@ -232,12 +234,7 @@ export class WebhooksAPI { id: Snowflake, token: string, messageId: Snowflake, - { - thread_id, - with_components, - files, - ...body - }: RESTPatchAPIWebhookWithTokenMessageJSONBody & RESTPatchAPIWebhookWithTokenMessageQuery & { files?: RawFile[] }, + { thread_id, with_components, files, ...body }: EditWebhookMessageOptions, { signal }: Pick = {}, ) { return this.rest.patch(Routes.webhookMessage(id, token, messageId), {