feat(core): Add AbortSignal support. (#9042)

* feat: add abort signal to guilds api

* feat: add to application commands, channels, and users classes

* chore: finish up

* chore: centralize types

* chore: make requested changes

* chore: make requested changes

* refactor: consistently use empty objects

* Update packages/core/src/api/webhook.ts

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>

* chore: make requested changes

* refactor: update `setVoiceState` after rebase

* chore: requested changes

* refactor: use -types interface for query

---------

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
This commit is contained in:
Suneet Tipirneni
2023-04-01 17:11:37 -04:00
committed by GitHub
parent e2f39ccc32
commit 907eb1b470
12 changed files with 959 additions and 444 deletions

View File

@@ -1,4 +1,4 @@
import { makeURLSearchParams, type REST } from '@discordjs/rest'; import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest';
import { import {
Routes, Routes,
type RESTGetAPIApplicationCommandPermissionsResult, type RESTGetAPIApplicationCommandPermissionsResult,
@@ -26,11 +26,17 @@ export class ApplicationCommandsAPI {
* *
* @see {@link https://discord.com/developers/docs/interactions/application-commands#get-global-application-commands} * @see {@link https://discord.com/developers/docs/interactions/application-commands#get-global-application-commands}
* @param applicationId - The application id to fetch commands for * @param applicationId - The application id to fetch commands for
* @param query - The query options to use when fetching commands
* @param options - The options to use when fetching commands * @param options - The options to use when fetching commands
*/ */
public async getGlobalCommands(applicationId: Snowflake, options: RESTGetAPIApplicationCommandsQuery = {}) { public async getGlobalCommands(
applicationId: Snowflake,
query: RESTGetAPIApplicationCommandsQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.applicationCommands(applicationId), { return this.rest.get(Routes.applicationCommands(applicationId), {
query: makeURLSearchParams(options), query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIApplicationCommandsResult>; }) as Promise<RESTGetAPIApplicationCommandsResult>;
} }
@@ -39,11 +45,17 @@ export class ApplicationCommandsAPI {
* *
* @see {@link https://discord.com/developers/docs/interactions/application-commands#create-global-application-command} * @see {@link https://discord.com/developers/docs/interactions/application-commands#create-global-application-command}
* @param applicationId - The application id to create the command for * @param applicationId - The application id to create the command for
* @param data - The data to use when creating the command * @param body - The data to use when creating the command
* @param options - The options to use when creating the command
*/ */
public async createGlobalCommand(applicationId: Snowflake, data: RESTPostAPIApplicationCommandsJSONBody) { public async createGlobalCommand(
applicationId: Snowflake,
body: RESTPostAPIApplicationCommandsJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.applicationCommands(applicationId), { return this.rest.post(Routes.applicationCommands(applicationId), {
body: data, body,
signal,
}) as Promise<RESTPostAPIApplicationCommandsResult>; }) as Promise<RESTPostAPIApplicationCommandsResult>;
} }
@@ -53,11 +65,16 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#get-global-application-command} * @see {@link https://discord.com/developers/docs/interactions/application-commands#get-global-application-command}
* @param applicationId - The application id to fetch the command from * @param applicationId - The application id to fetch the command from
* @param commandId - The command id to fetch * @param commandId - The command id to fetch
* @param options - The options to use when fetching the command
*/ */
public async getGlobalCommand(applicationId: Snowflake, commandId: Snowflake) { public async getGlobalCommand(
return this.rest.get( applicationId: Snowflake,
Routes.applicationCommand(applicationId, commandId), commandId: Snowflake,
) as Promise<RESTGetAPIApplicationCommandResult>; { signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.applicationCommand(applicationId, commandId), {
signal,
}) as Promise<RESTGetAPIApplicationCommandResult>;
} }
/** /**
@@ -66,15 +83,18 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#edit-global-application-command} * @see {@link https://discord.com/developers/docs/interactions/application-commands#edit-global-application-command}
* @param applicationId - The application id of the command * @param applicationId - The application id of the command
* @param commandId - The id of the command to edit * @param commandId - The id of the command to edit
* @param data - The data to use when editing the command * @param body - The data to use when editing the command
* @param options - The options for editing the command
*/ */
public async editGlobalCommand( public async editGlobalCommand(
applicationId: Snowflake, applicationId: Snowflake,
commandId: Snowflake, commandId: Snowflake,
data: RESTPatchAPIApplicationCommandJSONBody, body: RESTPatchAPIApplicationCommandJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.patch(Routes.applicationCommand(applicationId, commandId), { return this.rest.patch(Routes.applicationCommand(applicationId, commandId), {
body: data, body,
signal,
}) as Promise<RESTPatchAPIApplicationCommandResult>; }) as Promise<RESTPatchAPIApplicationCommandResult>;
} }
@@ -84,9 +104,14 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#delete-global-application-command} * @see {@link https://discord.com/developers/docs/interactions/application-commands#delete-global-application-command}
* @param applicationId - The application id of the command * @param applicationId - The application id of the command
* @param commandId - The id of the command to delete * @param commandId - The id of the command to delete
* @param options - The options for deleting a command
*/ */
public async deleteGlobalCommand(applicationId: Snowflake, commandId: Snowflake) { public async deleteGlobalCommand(
await this.rest.delete(Routes.applicationCommand(applicationId, commandId)); applicationId: Snowflake,
commandId: Snowflake,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.delete(Routes.applicationCommand(applicationId, commandId), { signal });
} }
/** /**
@@ -94,11 +119,17 @@ export class ApplicationCommandsAPI {
* *
* @see {@link https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands} * @see {@link https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-global-application-commands}
* @param applicationId - The application id to overwrite commands for * @param applicationId - The application id to overwrite commands for
* @param data - The data to use when overwriting commands * @param body - The data to use when overwriting commands
* @param options - The options for overwriting commands
*/ */
public async bulkOverwriteGlobalCommands(applicationId: Snowflake, data: RESTPutAPIApplicationCommandsJSONBody) { public async bulkOverwriteGlobalCommands(
applicationId: Snowflake,
body: RESTPutAPIApplicationCommandsJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.put(Routes.applicationCommands(applicationId), { return this.rest.put(Routes.applicationCommands(applicationId), {
body: data, body,
signal,
}) as Promise<RESTPutAPIApplicationCommandsResult>; }) as Promise<RESTPutAPIApplicationCommandsResult>;
} }
@@ -108,15 +139,18 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#get-guild-application-commands} * @see {@link https://discord.com/developers/docs/interactions/application-commands#get-guild-application-commands}
* @param applicationId - The application id to fetch commands for * @param applicationId - The application id to fetch commands for
* @param guildId - The guild id to fetch commands for * @param guildId - The guild id to fetch commands for
* @param data - The data to use when fetching commands * @param query - The data to use when fetching commands
* @param options - The options to use when fetching commands
*/ */
public async getGuildCommands( public async getGuildCommands(
applicationId: Snowflake, applicationId: Snowflake,
guildId: Snowflake, guildId: Snowflake,
data: RESTGetAPIApplicationGuildCommandsQuery = {}, query: RESTGetAPIApplicationGuildCommandsQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.get(Routes.applicationGuildCommands(applicationId, guildId), { return this.rest.get(Routes.applicationGuildCommands(applicationId, guildId), {
query: makeURLSearchParams(data), query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIApplicationCommandsResult>; }) as Promise<RESTGetAPIApplicationCommandsResult>;
} }
@@ -126,15 +160,18 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command} * @see {@link https://discord.com/developers/docs/interactions/application-commands#create-guild-application-command}
* @param applicationId - The application id to create the command for * @param applicationId - The application id to create the command for
* @param guildId - The guild id to create the command for * @param guildId - The guild id to create the command for
* @param data - The data to use when creating the command * @param body - The data to use when creating the command
* @param options - The options to use when creating the command
*/ */
public async createGuildCommand( public async createGuildCommand(
applicationId: Snowflake, applicationId: Snowflake,
guildId: Snowflake, guildId: Snowflake,
data: RESTPostAPIApplicationCommandsJSONBody, body: RESTPostAPIApplicationCommandsJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.post(Routes.applicationGuildCommands(applicationId, guildId), { return this.rest.post(Routes.applicationGuildCommands(applicationId, guildId), {
body: data, body,
signal,
}) as Promise<RESTPostAPIApplicationCommandsResult>; }) as Promise<RESTPostAPIApplicationCommandsResult>;
} }
@@ -145,11 +182,17 @@ export class ApplicationCommandsAPI {
* @param applicationId - The application id to fetch the command from * @param applicationId - The application id to fetch the command from
* @param guildId - The guild id to fetch the command from * @param guildId - The guild id to fetch the command from
* @param commandId - The command id to fetch * @param commandId - The command id to fetch
* @param options - The options to use when fetching the command
*/ */
public async getGuildCommand(applicationId: Snowflake, guildId: Snowflake, commandId: Snowflake) { public async getGuildCommand(
return this.rest.get( applicationId: Snowflake,
Routes.applicationGuildCommand(applicationId, guildId, commandId), guildId: Snowflake,
) as Promise<RESTGetAPIApplicationCommandResult>; commandId: Snowflake,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.applicationGuildCommand(applicationId, guildId, commandId), {
signal,
}) as Promise<RESTGetAPIApplicationCommandResult>;
} }
/** /**
@@ -159,16 +202,19 @@ export class ApplicationCommandsAPI {
* @param applicationId - The application id of the command * @param applicationId - The application id of the command
* @param guildId - The guild id of the command * @param guildId - The guild id of the command
* @param commandId - The command id to edit * @param commandId - The command id to edit
* @param data - The data to use when editing the command * @param body - The data to use when editing the command
* @param options - The options to use when editing the command
*/ */
public async editGuildCommand( public async editGuildCommand(
applicationId: Snowflake, applicationId: Snowflake,
guildId: Snowflake, guildId: Snowflake,
commandId: Snowflake, commandId: Snowflake,
data: RESTPatchAPIApplicationCommandJSONBody, body: RESTPatchAPIApplicationCommandJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.patch(Routes.applicationGuildCommand(applicationId, guildId, commandId), { return this.rest.patch(Routes.applicationGuildCommand(applicationId, guildId, commandId), {
body: data, body,
signal,
}) as Promise<RESTPatchAPIApplicationCommandResult>; }) as Promise<RESTPatchAPIApplicationCommandResult>;
} }
@@ -179,9 +225,15 @@ export class ApplicationCommandsAPI {
* @param applicationId - The application id of the command * @param applicationId - The application id of the command
* @param guildId - The guild id of the command * @param guildId - The guild id of the command
* @param commandId - The id of the command to delete * @param commandId - The id of the command to delete
* @param options - The options for deleting the command
*/ */
public async deleteGuildCommand(applicationId: Snowflake, guildId: Snowflake, commandId: Snowflake) { public async deleteGuildCommand(
await this.rest.delete(Routes.applicationGuildCommand(applicationId, guildId, commandId)); applicationId: Snowflake,
guildId: Snowflake,
commandId: Snowflake,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.delete(Routes.applicationGuildCommand(applicationId, guildId, commandId), { signal });
} }
/** /**
@@ -190,15 +242,18 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-guild-application-commands} * @see {@link https://discord.com/developers/docs/interactions/application-commands#bulk-overwrite-guild-application-commands}
* @param applicationId - The application id to overwrite commands for * @param applicationId - The application id to overwrite commands for
* @param guildId - The guild id to overwrite commands for * @param guildId - The guild id to overwrite commands for
* @param data - The data to use when overwriting commands * @param body - The data to use when overwriting commands
* @param options - The options to use when overwriting the commands
*/ */
public async bulkOverwriteGuildCommands( public async bulkOverwriteGuildCommands(
applicationId: Snowflake, applicationId: Snowflake,
guildId: Snowflake, guildId: Snowflake,
data: RESTPutAPIApplicationCommandsJSONBody, body: RESTPutAPIApplicationCommandsJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.put(Routes.applicationGuildCommands(applicationId, guildId), { return this.rest.put(Routes.applicationGuildCommands(applicationId, guildId), {
body: data, body,
signal,
}) as Promise<RESTPutAPIApplicationCommandsResult>; }) as Promise<RESTPutAPIApplicationCommandsResult>;
} }
@@ -209,11 +264,17 @@ export class ApplicationCommandsAPI {
* @param applicationId - The application id to get the permissions for * @param applicationId - The application id to get the permissions for
* @param guildId - The guild id of the command * @param guildId - The guild id of the command
* @param commandId - The command id to get the permissions for * @param commandId - The command id to get the permissions for
* @param options - The option for fetching the command
*/ */
public async getGuildCommandPermissions(applicationId: Snowflake, guildId: Snowflake, commandId: Snowflake) { public async getGuildCommandPermissions(
return this.rest.get( applicationId: Snowflake,
Routes.applicationCommandPermissions(applicationId, guildId, commandId), guildId: Snowflake,
) as Promise<RESTGetAPIApplicationCommandPermissionsResult>; commandId: Snowflake,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.applicationCommandPermissions(applicationId, guildId, commandId), {
signal,
}) as Promise<RESTGetAPIApplicationCommandPermissionsResult>;
} }
/** /**
@@ -222,11 +283,16 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#get-application-command-permissions} * @see {@link https://discord.com/developers/docs/interactions/application-commands#get-application-command-permissions}
* @param applicationId - The application id to get the permissions for * @param applicationId - The application id to get the permissions for
* @param guildId - The guild id to get the permissions for * @param guildId - The guild id to get the permissions for
* @param options - The options for fetching permissions
*/ */
public async getGuildCommandsPermissions(applicationId: Snowflake, guildId: Snowflake) { public async getGuildCommandsPermissions(
return this.rest.get( applicationId: Snowflake,
Routes.guildApplicationCommandsPermissions(applicationId, guildId), guildId: Snowflake,
) as Promise<RESTGetAPIGuildApplicationCommandsPermissionsResult>; { signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.guildApplicationCommandsPermissions(applicationId, guildId), {
signal,
}) as Promise<RESTGetAPIGuildApplicationCommandsPermissionsResult>;
} }
/** /**
@@ -237,19 +303,22 @@ export class ApplicationCommandsAPI {
* @param applicationId - The application id to edit the permissions for * @param applicationId - The application id to edit the permissions for
* @param guildId - The guild id to edit the permissions for * @param guildId - The guild id to edit the permissions for
* @param commandId - The id of the command to edit the permissions for * @param commandId - The id of the command to edit the permissions for
* @param data - The data to use when editing the permissions * @param body - The data to use when editing the permissions
* @param options - The options to use when editing the permissions
*/ */
public async editGuildCommandPermissions( public async editGuildCommandPermissions(
userToken: string, userToken: string,
applicationId: Snowflake, applicationId: Snowflake,
guildId: Snowflake, guildId: Snowflake,
commandId: Snowflake, commandId: Snowflake,
data: RESTPutAPIApplicationCommandPermissionsJSONBody, body: RESTPutAPIApplicationCommandPermissionsJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.put(Routes.applicationCommandPermissions(applicationId, guildId, commandId), { return this.rest.put(Routes.applicationCommandPermissions(applicationId, guildId, commandId), {
headers: { Authorization: `Bearer ${userToken.replace('Bearer ', '')}` }, headers: { Authorization: `Bearer ${userToken.replace('Bearer ', '')}` },
auth: false, auth: false,
body: data, body,
signal,
}) as Promise<RESTPutAPIApplicationCommandPermissionsResult>; }) as Promise<RESTPutAPIApplicationCommandPermissionsResult>;
} }
} }

View File

@@ -1,4 +1,4 @@
import { makeURLSearchParams, type RawFile, type REST } from '@discordjs/rest'; import { makeURLSearchParams, type RawFile, type REST, type RequestData } from '@discordjs/rest';
import { import {
Routes, Routes,
type RESTDeleteAPIChannelResult, type RESTDeleteAPIChannelResult,
@@ -33,15 +33,18 @@ export class ChannelsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#create-message} * @see {@link https://discord.com/developers/docs/resources/channel#create-message}
* @param channelId - The id of the channel to send the message in * @param channelId - The id of the channel to send the message in
* @param data - The data to use when sending the message * @param body - The data to use when sending the message
* @param options - The options to use when sending the message
*/ */
public async createMessage( public async createMessage(
channelId: Snowflake, channelId: Snowflake,
{ files, ...body }: RESTPostAPIChannelMessageJSONBody & { files?: RawFile[] }, { files, ...body }: RESTPostAPIChannelMessageJSONBody & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.post(Routes.channelMessages(channelId), { return this.rest.post(Routes.channelMessages(channelId), {
files, files,
body, body,
signal,
}) as Promise<RESTPostAPIChannelMessageResult>; }) as Promise<RESTPostAPIChannelMessageResult>;
} }
@@ -51,16 +54,19 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#edit-message} * @see {@link https://discord.com/developers/docs/resources/channel#edit-message}
* @param channelId - The id of the channel the message is in * @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to edit * @param messageId - The id of the message to edit
* @param data - The data to use when editing the message * @param body - The data to use when editing the message
* @param options - The options to use when editing the message
*/ */
public async editMessage( public async editMessage(
channelId: Snowflake, channelId: Snowflake,
messageId: Snowflake, messageId: Snowflake,
{ files, ...body }: RESTPostAPIChannelMessageJSONBody & { files?: RawFile[] }, { files, ...body }: RESTPostAPIChannelMessageJSONBody & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'>,
) { ) {
return this.rest.patch(Routes.channelMessage(channelId, messageId), { return this.rest.patch(Routes.channelMessage(channelId, messageId), {
files, files,
body, body,
signal,
}) as Promise<RESTPatchAPIChannelMessageResult>; }) as Promise<RESTPatchAPIChannelMessageResult>;
} }
@@ -71,16 +77,19 @@ export class ChannelsAPI {
* @param channelId - The id of the channel the message is in * @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to get the reactions for * @param messageId - The id of the message to get the reactions for
* @param emoji - The emoji to get the reactions for * @param emoji - The emoji to get the reactions for
* @param options - The options to use when fetching the reactions * @param query - The query options to use when fetching the reactions
* @param options - The options for fetching the message reactions
*/ */
public async getMessageReactions( public async getMessageReactions(
channelId: Snowflake, channelId: Snowflake,
messageId: Snowflake, messageId: Snowflake,
emoji: string, emoji: string,
options: RESTGetAPIChannelMessageReactionUsersQuery = {}, query: RESTGetAPIChannelMessageReactionUsersQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.get(Routes.channelMessageReaction(channelId, messageId, encodeURIComponent(emoji)), { return this.rest.get(Routes.channelMessageReaction(channelId, messageId, encodeURIComponent(emoji)), {
query: makeURLSearchParams(options), query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIChannelMessageReactionUsersResult>; }) as Promise<RESTGetAPIChannelMessageReactionUsersResult>;
} }
@@ -91,9 +100,17 @@ export class ChannelsAPI {
* @param channelId - The id of the channel the message is in * @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to delete the reaction for * @param messageId - The id of the message to delete the reaction for
* @param emoji - The emoji to delete the reaction for * @param emoji - The emoji to delete the reaction for
* @param options - The options for deleting the reaction
*/ */
public async deleteOwnMessageReaction(channelId: Snowflake, messageId: Snowflake, emoji: string) { public async deleteOwnMessageReaction(
await this.rest.delete(Routes.channelMessageOwnReaction(channelId, messageId, encodeURIComponent(emoji))); channelId: Snowflake,
messageId: Snowflake,
emoji: string,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.delete(Routes.channelMessageOwnReaction(channelId, messageId, encodeURIComponent(emoji)), {
signal,
});
} }
/** /**
@@ -104,9 +121,18 @@ export class ChannelsAPI {
* @param messageId - The id of the message to delete the reaction for * @param messageId - The id of the message to delete the reaction for
* @param emoji - The emoji to delete the reaction for * @param emoji - The emoji to delete the reaction for
* @param userId - The id of the user to delete the reaction for * @param userId - The id of the user to delete the reaction for
* @param options - The options for deleting the reaction
*/ */
public async deleteUserMessageReaction(channelId: Snowflake, messageId: Snowflake, emoji: string, userId: Snowflake) { public async deleteUserMessageReaction(
await this.rest.delete(Routes.channelMessageUserReaction(channelId, messageId, encodeURIComponent(emoji), userId)); channelId: Snowflake,
messageId: Snowflake,
emoji: string,
userId: Snowflake,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.delete(Routes.channelMessageUserReaction(channelId, messageId, encodeURIComponent(emoji), userId), {
signal,
});
} }
/** /**
@@ -115,9 +141,14 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#delete-all-reactions} * @see {@link https://discord.com/developers/docs/resources/channel#delete-all-reactions}
* @param channelId - The id of the channel the message is in * @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to delete the reactions for * @param messageId - The id of the message to delete the reactions for
* @param options - The options for deleting the reactions
*/ */
public async deleteAllMessageReactions(channelId: Snowflake, messageId: Snowflake) { public async deleteAllMessageReactions(
await this.rest.delete(Routes.channelMessageAllReactions(channelId, messageId)); channelId: Snowflake,
messageId: Snowflake,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.delete(Routes.channelMessageAllReactions(channelId, messageId), { signal });
} }
/** /**
@@ -127,9 +158,15 @@ export class ChannelsAPI {
* @param channelId - The id of the channel the message is in * @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to delete the reactions for * @param messageId - The id of the message to delete the reactions for
* @param emoji - The emoji to delete the reactions for * @param emoji - The emoji to delete the reactions for
* @param options - The options for deleting the reactions
*/ */
public async deleteAllMessageReactionsForEmoji(channelId: Snowflake, messageId: Snowflake, emoji: string) { public async deleteAllMessageReactionsForEmoji(
await this.rest.delete(Routes.channelMessageReaction(channelId, messageId, encodeURIComponent(emoji))); channelId: Snowflake,
messageId: Snowflake,
emoji: string,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.delete(Routes.channelMessageReaction(channelId, messageId, encodeURIComponent(emoji)), { signal });
} }
/** /**
@@ -139,9 +176,15 @@ export class ChannelsAPI {
* @param channelId - The id of the channel the message is in * @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to add the reaction to * @param messageId - The id of the message to add the reaction to
* @param emoji - The emoji to add the reaction with * @param emoji - The emoji to add the reaction with
* @param options - The options for adding the reaction
*/ */
public async addMessageReaction(channelId: Snowflake, messageId: Snowflake, emoji: string) { public async addMessageReaction(
await this.rest.put(Routes.channelMessageOwnReaction(channelId, messageId, encodeURIComponent(emoji))); channelId: Snowflake,
messageId: Snowflake,
emoji: string,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.put(Routes.channelMessageOwnReaction(channelId, messageId, encodeURIComponent(emoji)), { signal });
} }
/** /**
@@ -149,9 +192,10 @@ export class ChannelsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#get-channel} * @see {@link https://discord.com/developers/docs/resources/channel#get-channel}
* @param channelId - The id of the channel * @param channelId - The id of the channel
* @param options - The options for fetching the channel
*/ */
public async get(channelId: Snowflake) { public async get(channelId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.channel(channelId)) as Promise<RESTGetAPIChannelResult>; return this.rest.get(Routes.channel(channelId), { signal }) as Promise<RESTGetAPIChannelResult>;
} }
/** /**
@@ -159,10 +203,15 @@ export class ChannelsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#modify-channel} * @see {@link https://discord.com/developers/docs/resources/channel#modify-channel}
* @param channelId - The id of the channel to edit * @param channelId - The id of the channel to edit
* @param data - The new channel data * @param body - The new channel data
* @param options - The options for editing the channel
*/ */
public async edit(channelId: Snowflake, data: RESTPatchAPIChannelJSONBody) { public async edit(
return this.rest.patch(Routes.channel(channelId), { body: data }) as Promise<RESTPatchAPIChannelResult>; channelId: Snowflake,
body: RESTPatchAPIChannelJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.patch(Routes.channel(channelId), { body, signal }) as Promise<RESTPatchAPIChannelResult>;
} }
/** /**
@@ -170,9 +219,10 @@ export class ChannelsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#deleteclose-channel} * @see {@link https://discord.com/developers/docs/resources/channel#deleteclose-channel}
* @param channelId - The id of the channel to delete * @param channelId - The id of the channel to delete
* @param options - The options for deleting the channel
*/ */
public async delete(channelId: Snowflake) { public async delete(channelId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.delete(Routes.channel(channelId)) as Promise<RESTDeleteAPIChannelResult>; return this.rest.delete(Routes.channel(channelId), { signal }) as Promise<RESTDeleteAPIChannelResult>;
} }
/** /**
@@ -180,11 +230,17 @@ export class ChannelsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#get-channel-messages} * @see {@link https://discord.com/developers/docs/resources/channel#get-channel-messages}
* @param channelId - The id of the channel to fetch messages from * @param channelId - The id of the channel to fetch messages from
* @param options - The options to use when fetching messages * @param query - The query options to use when fetching messages
* @param options - The options for fetching the messages
*/ */
public async getMessages(channelId: Snowflake, options: RESTGetAPIChannelMessagesQuery = {}) { public async getMessages(
channelId: Snowflake,
query: RESTGetAPIChannelMessagesQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.channelMessages(channelId), { return this.rest.get(Routes.channelMessages(channelId), {
query: makeURLSearchParams(options), query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIChannelMessagesResult>; }) as Promise<RESTGetAPIChannelMessagesResult>;
} }
@@ -193,9 +249,10 @@ export class ChannelsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#trigger-typing-indicator} * @see {@link https://discord.com/developers/docs/resources/channel#trigger-typing-indicator}
* @param channelId - The id of the channel to show the typing indicator in * @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) { public async showTyping(channelId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.post(Routes.channelTyping(channelId)); await this.rest.post(Routes.channelTyping(channelId), { signal });
} }
/** /**
@@ -203,9 +260,10 @@ export class ChannelsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#get-pinned-messages} * @see {@link https://discord.com/developers/docs/resources/channel#get-pinned-messages}
* @param channelId - The id of the channel to fetch pinned messages from * @param channelId - The id of the channel to fetch pinned messages from
* @param options - The options for fetching the pinned messages
*/ */
public async getPins(channelId: Snowflake) { public async getPins(channelId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.channelPins(channelId)) as Promise<RESTGetAPIChannelPinsResult>; return this.rest.get(Routes.channelPins(channelId), { signal }) as Promise<RESTGetAPIChannelPinsResult>;
} }
/** /**
@@ -214,10 +272,14 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#pin-message} * @see {@link https://discord.com/developers/docs/resources/channel#pin-message}
* @param channelId - The id of the channel to pin the message in * @param channelId - The id of the channel to pin the message in
* @param messageId - The id of the message to pin * @param messageId - The id of the message to pin
* @param reason - The reason for pinning the message * @param options - The options for pinning the message
*/ */
public async pinMessage(channelId: Snowflake, messageId: Snowflake, reason?: string) { public async pinMessage(
await this.rest.put(Routes.channelPin(channelId, messageId), { reason }); channelId: Snowflake,
messageId: Snowflake,
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) {
await this.rest.put(Routes.channelPin(channelId, messageId), { reason, signal });
} }
/** /**
@@ -226,10 +288,14 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#delete-message} * @see {@link https://discord.com/developers/docs/resources/channel#delete-message}
* @param channelId - The id of the channel the message is in * @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to delete * @param messageId - The id of the message to delete
* @param reason - The reason for deleting the message * @param options - The options for deleting the message
*/ */
public async deleteMessage(channelId: Snowflake, messageId: Snowflake, reason?: string) { public async deleteMessage(
await this.rest.delete(Routes.channelMessage(channelId, messageId), { reason }); channelId: Snowflake,
messageId: Snowflake,
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) {
await this.rest.delete(Routes.channelMessage(channelId, messageId), { reason, signal });
} }
/** /**
@@ -238,9 +304,14 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#bulk-delete-messages} * @see {@link https://discord.com/developers/docs/resources/channel#bulk-delete-messages}
* @param channelId - The id of the channel the messages are in * @param channelId - The id of the channel the messages are in
* @param messageIds - The ids of the messages to delete * @param messageIds - The ids of the messages to delete
* @param options - The options for deleting the messages
*/ */
public async bulkDeleteMessages(channelId: Snowflake, messageIds: Snowflake[], reason?: string): Promise<void> { public async bulkDeleteMessages(
await this.rest.post(Routes.channelBulkDelete(channelId), { reason, body: { messages: messageIds } }); channelId: Snowflake,
messageIds: Snowflake[],
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
): Promise<void> {
await this.rest.post(Routes.channelBulkDelete(channelId), { reason, body: { messages: messageIds }, signal });
} }
/** /**
@@ -249,9 +320,12 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#get-channel-message} * @see {@link https://discord.com/developers/docs/resources/channel#get-channel-message}
* @param channelId - The id of the channel the message is in * @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to fetch * @param messageId - The id of the message to fetch
* @param options - The options for fetching the message
*/ */
public async getMessage(channelId: Snowflake, messageId: Snowflake) { public async getMessage(channelId: Snowflake, messageId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.channelMessage(channelId, messageId)) as Promise<RESTGetAPIChannelMessageResult>; return this.rest.get(Routes.channelMessage(channelId, messageId), {
signal,
}) as Promise<RESTGetAPIChannelMessageResult>;
} }
/** /**
@@ -260,11 +334,16 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#crosspost-message} * @see {@link https://discord.com/developers/docs/resources/channel#crosspost-message}
* @param channelId - The id of the channel the message is in * @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to crosspost * @param messageId - The id of the message to crosspost
* @param options - The options for crossposting the message
*/ */
public async crosspostMessage(channelId: Snowflake, messageId: Snowflake) { public async crosspostMessage(
return this.rest.post( channelId: Snowflake,
Routes.channelMessageCrosspost(channelId, messageId), messageId: Snowflake,
) as Promise<RESTPostAPIChannelMessageCrosspostResult>; { signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.channelMessageCrosspost(channelId, messageId), {
signal,
}) as Promise<RESTPostAPIChannelMessageCrosspostResult>;
} }
/** /**
@@ -273,10 +352,14 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#unpin-message} * @see {@link https://discord.com/developers/docs/resources/channel#unpin-message}
* @param channelId - The id of the channel to unpin the message in * @param channelId - The id of the channel to unpin the message in
* @param messageId - The id of the message to unpin * @param messageId - The id of the message to unpin
* @param reason - The reason for unpinning the message * @param options - The options for unpinning the message
*/ */
public async unpinMessage(channelId: Snowflake, messageId: Snowflake, reason?: string) { public async unpinMessage(
await this.rest.delete(Routes.channelPin(channelId, messageId), { reason }); channelId: Snowflake,
messageId: Snowflake,
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) {
await this.rest.delete(Routes.channelPin(channelId, messageId), { reason, signal });
} }
/** /**
@@ -285,10 +368,16 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#follow-announcement-channel} * @see {@link https://discord.com/developers/docs/resources/channel#follow-announcement-channel}
* @param channelId - The id of the announcement channel to follow * @param channelId - The id of the announcement channel to follow
* @param webhookChannelId - The id of the webhook channel to follow the announcements in * @param webhookChannelId - The id of the webhook channel to follow the announcements in
* @param options - The options for following the announcement channel
*/ */
public async followAnnouncements(channelId: Snowflake, webhookChannelId: Snowflake) { public async followAnnouncements(
channelId: Snowflake,
webhookChannelId: Snowflake,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.channelFollowers(channelId), { return this.rest.post(Routes.channelFollowers(channelId), {
body: { webhook_channel_id: webhookChannelId }, body: { webhook_channel_id: webhookChannelId },
signal,
}) as Promise<RESTPostAPIChannelFollowersResult>; }) as Promise<RESTPostAPIChannelFollowersResult>;
} }
@@ -297,12 +386,18 @@ export class ChannelsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#create-channel-invite} * @see {@link https://discord.com/developers/docs/resources/channel#create-channel-invite}
* @param channelId - The id of the channel to create an invite for * @param channelId - The id of the channel to create an invite for
* @param data - The data to use when creating the invite * @param body - The data to use when creating the invite
* @param options - The options for creating the invite
*/ */
public async createInvite(channelId: Snowflake, data: RESTPostAPIChannelInviteJSONBody, reason?: string) { public async createInvite(
channelId: Snowflake,
body: RESTPostAPIChannelInviteJSONBody,
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) {
return this.rest.post(Routes.channelInvites(channelId), { return this.rest.post(Routes.channelInvites(channelId), {
reason, reason,
body: data, body,
signal,
}) as Promise<RESTPostAPIChannelInviteResult>; }) as Promise<RESTPostAPIChannelInviteResult>;
} }
@@ -311,9 +406,10 @@ export class ChannelsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#get-channel-invites} * @see {@link https://discord.com/developers/docs/resources/channel#get-channel-invites}
* @param channelId - The id of the channel to fetch invites from * @param channelId - The id of the channel to fetch invites from
* @param options - The options for fetching the invites
*/ */
public async getInvites(channelId: Snowflake) { public async getInvites(channelId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.channelInvites(channelId)) as Promise<RESTGetAPIChannelInvitesResult>; return this.rest.get(Routes.channelInvites(channelId), { signal }) as Promise<RESTGetAPIChannelInvitesResult>;
} }
/** /**
@@ -323,15 +419,18 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#list-private-archived-threads} * @see {@link https://discord.com/developers/docs/resources/channel#list-private-archived-threads}
* @param channelId - The id of the channel to fetch archived threads from * @param channelId - The id of the channel to fetch archived threads from
* @param archivedStatus - The archived status of the threads to fetch * @param archivedStatus - The archived status of the threads to fetch
* @param options - The options to use when fetching archived threads * @param query - The options to use when fetching archived threads
* @param options - The options for fetching archived threads
*/ */
public async getArchivedThreads( public async getArchivedThreads(
channelId: Snowflake, channelId: Snowflake,
archivedStatus: 'private' | 'public', archivedStatus: 'private' | 'public',
options: RESTGetAPIChannelThreadsArchivedQuery = {}, query: RESTGetAPIChannelThreadsArchivedQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.get(Routes.channelThreads(channelId, archivedStatus), { return this.rest.get(Routes.channelThreads(channelId, archivedStatus), {
query: makeURLSearchParams(options), query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIChannelUsersThreadsArchivedResult>; }) as Promise<RESTGetAPIChannelUsersThreadsArchivedResult>;
} }
@@ -340,14 +439,17 @@ export class ChannelsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#list-joined-private-archived-threads} * @see {@link https://discord.com/developers/docs/resources/channel#list-joined-private-archived-threads}
* @param channelId - The id of the channel to fetch joined archived threads from * @param channelId - The id of the channel to fetch joined archived threads from
* @param options - The options to use when fetching joined archived threads * @param query - The options to use when fetching joined archived threads
* @param options - The options for fetching joined archived threads
*/ */
public async getJoinedPrivateArchivedThreads( public async getJoinedPrivateArchivedThreads(
channelId: Snowflake, channelId: Snowflake,
options: RESTGetAPIChannelThreadsArchivedQuery = {}, query: RESTGetAPIChannelThreadsArchivedQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.get(Routes.channelJoinedArchivedThreads(channelId), { return this.rest.get(Routes.channelJoinedArchivedThreads(channelId), {
query: makeURLSearchParams(options), query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIChannelUsersThreadsArchivedResult>; }) as Promise<RESTGetAPIChannelUsersThreadsArchivedResult>;
} }

File diff suppressed because it is too large Load Diff

View File

@@ -1,11 +1,11 @@
import type { RawFile, REST } from '@discordjs/rest'; import type { RawFile, RequestData, REST } from '@discordjs/rest';
import { InteractionResponseType, Routes } from 'discord-api-types/v10'; import { InteractionResponseType, Routes } from 'discord-api-types/v10';
import type { import type {
Snowflake,
APICommandAutocompleteInteractionResponseCallbackData, APICommandAutocompleteInteractionResponseCallbackData,
APIInteractionResponseCallbackData, APIInteractionResponseCallbackData,
APIModalInteractionResponseCallbackData, APIModalInteractionResponseCallbackData,
RESTGetAPIWebhookWithTokenMessageResult, RESTGetAPIWebhookWithTokenMessageResult,
Snowflake,
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
import type { WebhooksAPI } from './webhook.js'; import type { WebhooksAPI } from './webhook.js';
@@ -18,12 +18,14 @@ export class InteractionsAPI {
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response} * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response}
* @param interactionId - The id of the interaction * @param interactionId - The id of the interaction
* @param interactionToken - The token of the interaction * @param interactionToken - The token of the interaction
* @param data - The data to use when replying * @param body - The callback data to use when replying
* @param options - The options to use when replying
*/ */
public async reply( public async reply(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
{ files, ...data }: APIInteractionResponseCallbackData & { files?: RawFile[] }, { files, ...data }: APIInteractionResponseCallbackData & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
files, files,
@@ -32,6 +34,7 @@ export class InteractionsAPI {
type: InteractionResponseType.ChannelMessageWithSource, type: InteractionResponseType.ChannelMessageWithSource,
data, data,
}, },
signal,
}); });
} }
@@ -41,13 +44,15 @@ export class InteractionsAPI {
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response} * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response}
* @param interactionId - The id of the interaction * @param interactionId - The id of the interaction
* @param interactionToken - The token of the interaction * @param interactionToken - The token of the interaction
* @param options - The options to use when deferring
*/ */
public async defer(interactionId: Snowflake, interactionToken: string) { public async defer(interactionId: Snowflake, interactionToken: string, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
auth: false, auth: false,
body: { body: {
type: InteractionResponseType.DeferredChannelMessageWithSource, type: InteractionResponseType.DeferredChannelMessageWithSource,
}, },
signal,
}); });
} }
@@ -57,13 +62,19 @@ export class InteractionsAPI {
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response} * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response}
* @param interactionId - The id of the interaction * @param interactionId - The id of the interaction
* @param interactionToken - The token of the interaction * @param interactionToken - The token of the interaction
* @param options - The options to use when deferring
*/ */
public async deferMessageUpdate(interactionId: Snowflake, interactionToken: string) { public async deferMessageUpdate(
interactionId: Snowflake,
interactionToken: string,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
auth: false, auth: false,
body: { body: {
type: InteractionResponseType.DeferredMessageUpdate, type: InteractionResponseType.DeferredMessageUpdate,
}, },
signal,
}); });
} }
@@ -73,14 +84,16 @@ export class InteractionsAPI {
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-followup-message} * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-followup-message}
* @param applicationId - The application id of the interaction * @param applicationId - The application id of the interaction
* @param interactionToken - The token of the interaction * @param interactionToken - The token of the interaction
* @param data - The data to use when replying * @param body - The callback data to use when replying
* @param options - The options to use when replying
*/ */
public async followUp( public async followUp(
applicationId: Snowflake, applicationId: Snowflake,
interactionToken: string, interactionToken: string,
data: APIInteractionResponseCallbackData & { files?: RawFile[] }, body: APIInteractionResponseCallbackData & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
await this.webhooks.execute(applicationId, interactionToken, data); await this.webhooks.execute(applicationId, interactionToken, body, { signal });
} }
/** /**
@@ -90,16 +103,20 @@ export class InteractionsAPI {
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#edit-followup-message} * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#edit-followup-message}
* @param applicationId - The application id of the interaction * @param applicationId - The application id of the interaction
* @param interactionToken - The token of the interaction * @param interactionToken - The token of the interaction
* @param data - The data to use when editing the reply * @param callbackData - The callback data to use when editing the reply
* @param messageId - The id of the message to edit. If omitted, the original reply will be edited * @param messageId - The id of the message to edit. If omitted, the original reply will be edited
* @param options - The options to use when editing the reply
*/ */
public async editReply( public async editReply(
applicationId: Snowflake, applicationId: Snowflake,
interactionToken: string, interactionToken: string,
data: APIInteractionResponseCallbackData & { files?: RawFile[] }, callbackData: APIInteractionResponseCallbackData & { files?: RawFile[] },
messageId?: Snowflake | '@original', messageId?: Snowflake | '@original',
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.webhooks.editMessage(applicationId, interactionToken, messageId ?? '@original', data); return this.webhooks.editMessage(applicationId, interactionToken, messageId ?? '@original', callbackData, {
signal,
});
} }
/** /**
@@ -108,12 +125,19 @@ export class InteractionsAPI {
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response} * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#get-original-interaction-response}
* @param applicationId - The application id of the interaction * @param applicationId - The application id of the interaction
* @param interactionToken - The token of the interaction * @param interactionToken - The token of the interaction
* @param options - The options to use when fetching the reply
*/ */
public async getOriginalReply(applicationId: Snowflake, interactionToken: string) { public async getOriginalReply(
applicationId: Snowflake,
interactionToken: string,
{ signal }: Pick<RequestData, 'signal'>,
) {
return this.webhooks.getMessage( return this.webhooks.getMessage(
applicationId, applicationId,
interactionToken, interactionToken,
'@original', '@original',
{},
{ signal },
) as Promise<RESTGetAPIWebhookWithTokenMessageResult>; ) as Promise<RESTGetAPIWebhookWithTokenMessageResult>;
} }
@@ -125,9 +149,15 @@ export class InteractionsAPI {
* @param applicationId - The application id of the interaction * @param applicationId - The application id of the interaction
* @param interactionToken - The token of the interaction * @param interactionToken - The token of the interaction
* @param messageId - The id of the message to delete. If omitted, the original reply will be deleted * @param messageId - The id of the message to delete. If omitted, the original reply will be deleted
* @param options - The options to use when deleting the reply
*/ */
public async deleteReply(applicationId: Snowflake, interactionToken: string, messageId?: Snowflake | '@original') { public async deleteReply(
await this.webhooks.deleteMessage(applicationId, interactionToken, messageId ?? '@original'); applicationId: Snowflake,
interactionToken: string,
messageId?: Snowflake | '@original',
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.webhooks.deleteMessage(applicationId, interactionToken, messageId ?? '@original', {}, { signal });
} }
/** /**
@@ -136,12 +166,14 @@ export class InteractionsAPI {
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response} * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response}
* @param interactionId - The id of the interaction * @param interactionId - The id of the interaction
* @param interactionToken - The token of the interaction * @param interactionToken - The token of the interaction
* @param data - The data to use when updating the interaction * @param callbackData - The callback data to use when updating the interaction
* @param options - The options to use when updating the interaction
*/ */
public async updateMessage( public async updateMessage(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
{ files, ...data }: APIInteractionResponseCallbackData & { files?: RawFile[] }, { files, ...data }: APIInteractionResponseCallbackData & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
files, files,
@@ -150,6 +182,7 @@ export class InteractionsAPI {
type: InteractionResponseType.UpdateMessage, type: InteractionResponseType.UpdateMessage,
data, data,
}, },
signal,
}); });
} }
@@ -159,19 +192,22 @@ export class InteractionsAPI {
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response} * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response}
* @param interactionId - The id of the interaction * @param interactionId - The id of the interaction
* @param interactionToken - The token of the interaction * @param interactionToken - The token of the interaction
* @param data - Data for the autocomplete response * @param callbackData - The callback data for the autocomplete response
* @param options - The options to use when sending the autocomplete response
*/ */
public async createAutocompleteResponse( public async createAutocompleteResponse(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
data: APICommandAutocompleteInteractionResponseCallbackData, callbackData: APICommandAutocompleteInteractionResponseCallbackData,
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
auth: false, auth: false,
body: { body: {
type: InteractionResponseType.ApplicationCommandAutocompleteResult, type: InteractionResponseType.ApplicationCommandAutocompleteResult,
data, data: callbackData,
}, },
signal,
}); });
} }
@@ -181,19 +217,22 @@ export class InteractionsAPI {
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response} * @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response}
* @param interactionId - The id of the interaction * @param interactionId - The id of the interaction
* @param interactionToken - The token of the interaction * @param interactionToken - The token of the interaction
* @param data - The modal to send * @param callbackData - The modal callback data to send
* @param options - The options to use when sending the modal
*/ */
public async createModal( public async createModal(
interactionId: Snowflake, interactionId: Snowflake,
interactionToken: string, interactionToken: string,
data: APIModalInteractionResponseCallbackData, callbackData: APIModalInteractionResponseCallbackData,
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), { await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
auth: false, auth: false,
body: { body: {
type: InteractionResponseType.Modal, type: InteractionResponseType.Modal,
data, data: callbackData,
}, },
signal,
}); });
} }
} }

View File

@@ -1,4 +1,4 @@
import { makeURLSearchParams, type REST } from '@discordjs/rest'; import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest';
import { Routes, type RESTGetAPIInviteQuery, type RESTGetAPIInviteResult } from 'discord-api-types/v10'; import { Routes, type RESTGetAPIInviteQuery, type RESTGetAPIInviteResult } from 'discord-api-types/v10';
export class InvitesAPI { export class InvitesAPI {
@@ -9,10 +9,13 @@ export class InvitesAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/invite#get-invite} * @see {@link https://discord.com/developers/docs/resources/invite#get-invite}
* @param code - The invite code * @param code - The invite code
* @param query - The options to use when fetching the invite
* @param options - The options to use when fetching the invite
*/ */
public async get(code: string, options: RESTGetAPIInviteQuery = {}) { public async get(code: string, query: RESTGetAPIInviteQuery = {}, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.invite(code), { return this.rest.get(Routes.invite(code), {
query: makeURLSearchParams(options), query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIInviteResult>; }) as Promise<RESTGetAPIInviteResult>;
} }
@@ -21,9 +24,9 @@ export class InvitesAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/invite#delete-invite} * @see {@link https://discord.com/developers/docs/resources/invite#delete-invite}
* @param code - The invite code * @param code - The invite code
* @param reason - The reason for deleting the invite * @param options - The options to use when deleting the invite
*/ */
public async delete(code: string, reason?: string) { public async delete(code: string, { reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {}) {
await this.rest.delete(Routes.invite(code), { reason }); await this.rest.delete(Routes.invite(code), { reason, signal });
} }
} }

View File

@@ -1,6 +1,5 @@
import { URL } from 'node:url'; import { URL } from 'node:url';
import type { REST } from '@discordjs/rest'; import { type RequestData, type REST, makeURLSearchParams } from '@discordjs/rest';
import { makeURLSearchParams } from '@discordjs/rest';
import { import {
Routes, Routes,
RouteBases, RouteBases,
@@ -34,15 +33,20 @@ export class OAuth2API {
* Performs an OAuth2 token exchange, giving you an access token * Performs an OAuth2 token exchange, giving you an access token
* *
* @see {@link https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-access-token-exchange-example} * @see {@link https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-access-token-exchange-example}
* @param body - The body of the token exchange request
* @param options - The options for the token exchange request * @param options - The options for the token exchange request
*/ */
public async tokenExchange(options: RESTPostOAuth2AccessTokenURLEncodedData) { public async tokenExchange(
body: RESTPostOAuth2AccessTokenURLEncodedData,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.oauth2TokenExchange(), { return this.rest.post(Routes.oauth2TokenExchange(), {
body: makeURLSearchParams(options), body: makeURLSearchParams(body),
passThroughBody: true, passThroughBody: true,
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
}, },
signal,
}) as Promise<RESTPostOAuth2AccessTokenResult>; }) as Promise<RESTPostOAuth2AccessTokenResult>;
} }
@@ -50,15 +54,20 @@ export class OAuth2API {
* Refreshes an OAuth2 access token, giving you a new one * Refreshes an OAuth2 access token, giving you a new one
* *
* @see {@link https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-refresh-token-exchange-example} * @see {@link https://discord.com/developers/docs/topics/oauth2#authorization-code-grant-refresh-token-exchange-example}
* @param body - The options for the refresh token request
* @param options - The options for the refresh token request * @param options - The options for the refresh token request
*/ */
public async refreshToken(options: RESTPostOAuth2RefreshTokenURLEncodedData) { public async refreshToken(
body: RESTPostOAuth2RefreshTokenURLEncodedData,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.oauth2TokenExchange(), { return this.rest.post(Routes.oauth2TokenExchange(), {
body: makeURLSearchParams(options), body: makeURLSearchParams(body),
passThroughBody: true, passThroughBody: true,
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
}, },
signal,
}) as Promise<RESTPostOAuth2RefreshTokenResult>; }) as Promise<RESTPostOAuth2RefreshTokenResult>;
} }
@@ -68,15 +77,20 @@ export class OAuth2API {
* @remarks * @remarks
* This is primarily used for testing purposes * This is primarily used for testing purposes
* @see {@link https://discord.com/developers/docs/topics/oauth2#client-credentials-grant} * @see {@link https://discord.com/developers/docs/topics/oauth2#client-credentials-grant}
* @param body - The options for the client credentials grant request
* @param options - The options for the client credentials grant request * @param options - The options for the client credentials grant request
*/ */
public async getToken(options: RESTPostOAuth2ClientCredentialsURLEncodedData) { public async getToken(
body: RESTPostOAuth2ClientCredentialsURLEncodedData,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.oauth2TokenExchange(), { return this.rest.post(Routes.oauth2TokenExchange(), {
body: makeURLSearchParams(options), body: makeURLSearchParams(body),
passThroughBody: true, passThroughBody: true,
headers: { headers: {
'Content-Type': 'application/x-www-form-urlencoded', 'Content-Type': 'application/x-www-form-urlencoded',
}, },
signal,
}) as Promise<RESTPostOAuth2ClientCredentialsResult>; }) as Promise<RESTPostOAuth2ClientCredentialsResult>;
} }
@@ -84,17 +98,23 @@ export class OAuth2API {
* Fetches the current bot's application information * Fetches the current bot's application information
* *
* @see {@link https://discord.com/developers/docs/topics/oauth2#get-current-bot-application-information} * @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() { public async getCurrentBotApplicationInformation({ signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.oauth2CurrentApplication()) as Promise<RESTGetAPIOAuth2CurrentApplicationResult>; return this.rest.get(Routes.oauth2CurrentApplication(), {
signal,
}) as Promise<RESTGetAPIOAuth2CurrentApplicationResult>;
} }
/** /**
* Fetches the current authorization information * Fetches the current authorization information
* *
* @see {@link https://discord.com/developers/docs/topics/oauth2#get-current-authorization-information} * @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() { public async getCurrentAuthorizationInformation({ signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.oauth2CurrentAuthorization()) as Promise<RESTGetAPIOAuth2CurrentAuthorizationResult>; return this.rest.get(Routes.oauth2CurrentAuthorization(), {
signal,
}) as Promise<RESTGetAPIOAuth2CurrentAuthorizationResult>;
} }
} }

View File

@@ -1,4 +1,4 @@
import type { REST } from '@discordjs/rest'; import type { RequestData, REST } from '@discordjs/rest';
import { import {
Routes, Routes,
type RESTGetAPIApplicationRoleConnectionMetadataResult, type RESTGetAPIApplicationRoleConnectionMetadataResult,
@@ -15,11 +15,12 @@ export class RoleConnectionsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/application-role-connection-metadata#get-application-role-connection-metadata-records} * @see {@link https://discord.com/developers/docs/resources/application-role-connection-metadata#get-application-role-connection-metadata-records}
* @param applicationId - The id of the application to get role connection metadata records for * @param applicationId - The id of the application to get role connection metadata records for
* @param options - The options to use when fetching the role connection metadata records
*/ */
public async getMetadataRecords(applicationId: Snowflake) { public async getMetadataRecords(applicationId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get( return this.rest.get(Routes.applicationRoleConnectionMetadata(applicationId), {
Routes.applicationRoleConnectionMetadata(applicationId), signal,
) as Promise<RESTGetAPIApplicationRoleConnectionMetadataResult>; }) as Promise<RESTGetAPIApplicationRoleConnectionMetadataResult>;
} }
/** /**
@@ -27,14 +28,17 @@ export class RoleConnectionsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records} * @see {@link https://discord.com/developers/docs/resources/application-role-connection-metadata#update-application-role-connection-metadata-records}
* @param applicationId - The id of the application to update role connection metadata records for * @param applicationId - The id of the application to update role connection metadata records for
* @param options - The new role connection metadata records * @param body - The new role connection metadata records
* @param options - The options to use when updating the role connection metadata records
*/ */
public async updateMetadataRecords( public async updateMetadataRecords(
applicationId: Snowflake, applicationId: Snowflake,
options: RESTPutAPIApplicationCommandPermissionsJSONBody, body: RESTPutAPIApplicationCommandPermissionsJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.put(Routes.applicationRoleConnectionMetadata(applicationId), { return this.rest.put(Routes.applicationRoleConnectionMetadata(applicationId), {
body: options, body,
signal,
}) as Promise<RESTPutAPIApplicationRoleConnectionMetadataResult>; }) as Promise<RESTPutAPIApplicationRoleConnectionMetadataResult>;
} }
} }

View File

@@ -1,4 +1,4 @@
import type { REST } from '@discordjs/rest'; import type { RequestData, REST } from '@discordjs/rest';
import { import {
Routes, Routes,
type RESTGetAPIStickerResult, type RESTGetAPIStickerResult,
@@ -13,9 +13,10 @@ export class StickersAPI {
* Fetches all of the nitro sticker packs * Fetches all of the nitro sticker packs
* *
* @see {@link https://discord.com/developers/docs/resources/sticker#list-nitro-sticker-packs} * @see {@link https://discord.com/developers/docs/resources/sticker#list-nitro-sticker-packs}
* @param options - The options to use when fetching the sticker packs
*/ */
public async getNitroStickers() { public async getNitroStickers({ signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.nitroStickerPacks()) as Promise<RESTGetNitroStickerPacksResult>; return this.rest.get(Routes.nitroStickerPacks(), { signal }) as Promise<RESTGetNitroStickerPacksResult>;
} }
/** /**
@@ -23,8 +24,9 @@ export class StickersAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/sticker#get-sticker} * @see {@link https://discord.com/developers/docs/resources/sticker#get-sticker}
* @param stickerId - The id of the sticker * @param stickerId - The id of the sticker
* @param options - The options to use when fetching the sticker
*/ */
public async get(stickerId: Snowflake) { public async get(stickerId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.sticker(stickerId)) as Promise<RESTGetAPIStickerResult>; return this.rest.get(Routes.sticker(stickerId), { signal }) as Promise<RESTGetAPIStickerResult>;
} }
} }

View File

@@ -1,4 +1,4 @@
import type { RawFile, REST } from '@discordjs/rest'; import type { RawFile, RequestData, REST } from '@discordjs/rest';
import { import {
Routes, Routes,
type APIThreadChannel, type APIThreadChannel,
@@ -10,10 +10,6 @@ import {
type Snowflake, type Snowflake,
} from 'discord-api-types/v10'; } from 'discord-api-types/v10';
export interface StartThreadOptions extends RESTPostAPIChannelThreadsJSONBody {
message_id?: string;
}
export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody { export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody {
message: RESTPostAPIGuildForumThreadsJSONBody['message'] & { files?: RawFile[] }; message: RESTPostAPIGuildForumThreadsJSONBody['message'] & { files?: RawFile[] };
} }
@@ -26,9 +22,10 @@ export class ThreadsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#get-channel} * @see {@link https://discord.com/developers/docs/resources/channel#get-channel}
* @param threadId - The id of the thread * @param threadId - The id of the thread
* @param options - The options to use when fetching the thread
*/ */
public async get(threadId: Snowflake) { public async get(threadId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.channel(threadId)) as Promise<APIThreadChannel>; return this.rest.get(Routes.channel(threadId), { signal }) as Promise<APIThreadChannel>;
} }
/** /**
@@ -37,10 +34,20 @@ export class ThreadsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#start-thread-from-message} * @see {@link https://discord.com/developers/docs/resources/channel#start-thread-from-message}
* @see {@link https://discord.com/developers/docs/resources/channel#start-thread-without-message} * @see {@link https://discord.com/developers/docs/resources/channel#start-thread-without-message}
* @param channelId - The id of the channel to start the thread in * @param channelId - The id of the channel to start the thread in
* @param data - The data to use when starting the thread * @param body - The data to use when starting the thread
* @param messageId - The id of the message to start the thread from
* @param options - The options to use when starting the thread
*/ */
public async create(channelId: Snowflake, { message_id, ...body }: StartThreadOptions) { public async create(
return this.rest.post(Routes.threads(channelId, message_id), { body }) as Promise<RESTPostAPIChannelThreadsResult>; channelId: Snowflake,
body: RESTPostAPIChannelThreadsJSONBody,
messageId?: Snowflake,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.threads(channelId, messageId), {
body,
signal,
}) as Promise<RESTPostAPIChannelThreadsResult>;
} }
/** /**
@@ -48,9 +55,14 @@ export class ThreadsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#start-thread-in-forum-channel} * @see {@link https://discord.com/developers/docs/resources/channel#start-thread-in-forum-channel}
* @param channelId - The id of the forum channel to start the thread in * @param channelId - The id of the forum channel to start the thread in
* @param data - The data to use when starting the thread * @param body - The data to use when starting the thread
* @param options - The options to use when starting the thread
*/ */
public async createForumThread(channelId: Snowflake, { message, ...optionsBody }: StartForumThreadOptions) { public async createForumThread(
channelId: Snowflake,
{ message, ...optionsBody }: StartForumThreadOptions,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
const { files, ...messageBody } = message; const { files, ...messageBody } = message;
const body = { const body = {
@@ -58,7 +70,7 @@ export class ThreadsAPI {
message: messageBody, message: messageBody,
}; };
return this.rest.post(Routes.threads(channelId), { files, body }) as Promise<APIThreadChannel>; return this.rest.post(Routes.threads(channelId), { files, body, signal }) as Promise<APIThreadChannel>;
} }
/** /**
@@ -66,9 +78,10 @@ export class ThreadsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#join-thread} * @see {@link https://discord.com/developers/docs/resources/channel#join-thread}
* @param threadId - The id of the thread to join * @param threadId - The id of the thread to join
* @param options - The options to use when joining the thread
*/ */
public async join(threadId: Snowflake) { public async join(threadId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.put(Routes.threadMembers(threadId, '@me')); await this.rest.put(Routes.threadMembers(threadId, '@me'), { signal });
} }
/** /**
@@ -77,9 +90,10 @@ export class ThreadsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#add-thread-member} * @see {@link https://discord.com/developers/docs/resources/channel#add-thread-member}
* @param threadId - The id of the thread to add the member to * @param threadId - The id of the thread to add the member to
* @param userId - The id of the user to add to the thread * @param userId - The id of the user to add to the thread
* @param options - The options to use when adding the member to the thread
*/ */
public async addMember(threadId: Snowflake, userId: Snowflake) { public async addMember(threadId: Snowflake, userId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.put(Routes.threadMembers(threadId, userId)); await this.rest.put(Routes.threadMembers(threadId, userId), { signal });
} }
/** /**
@@ -87,9 +101,10 @@ export class ThreadsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#leave-thread} * @see {@link https://discord.com/developers/docs/resources/channel#leave-thread}
* @param threadId - The id of the thread to leave * @param threadId - The id of the thread to leave
* @param options - The options to use when leaving the thread
*/ */
public async leave(threadId: Snowflake) { public async leave(threadId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.delete(Routes.threadMembers(threadId, '@me')); await this.rest.delete(Routes.threadMembers(threadId, '@me'), { signal });
} }
/** /**
@@ -98,9 +113,10 @@ export class ThreadsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#remove-thread-member} * @see {@link https://discord.com/developers/docs/resources/channel#remove-thread-member}
* @param threadId - The id of the thread to remove the member from * @param threadId - The id of the thread to remove the member from
* @param userId - The id of the user to remove from the thread * @param userId - The id of the user to remove from the thread
* @param options - The options to use when removing the member from the thread
*/ */
public async removeMember(threadId: Snowflake, userId: Snowflake) { public async removeMember(threadId: Snowflake, userId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.delete(Routes.threadMembers(threadId, userId)); await this.rest.delete(Routes.threadMembers(threadId, userId), { signal });
} }
/** /**
@@ -109,9 +125,10 @@ export class ThreadsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#get-thread-member} * @see {@link https://discord.com/developers/docs/resources/channel#get-thread-member}
* @param threadId - The id of the thread to fetch the member from * @param threadId - The id of the thread to fetch the member from
* @param userId - The id of the user * @param userId - The id of the user
* @param options - The options to use when fetching the member
*/ */
public async getMember(threadId: Snowflake, userId: Snowflake) { public async getMember(threadId: Snowflake, userId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.threadMembers(threadId, userId)) as Promise<APIThreadMember>; return this.rest.get(Routes.threadMembers(threadId, userId), { signal }) as Promise<APIThreadMember>;
} }
/** /**
@@ -119,8 +136,9 @@ export class ThreadsAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/channel#list-thread-members} * @see {@link https://discord.com/developers/docs/resources/channel#list-thread-members}
* @param threadId - The id of the thread to fetch the members from * @param threadId - The id of the thread to fetch the members from
* @param options - The options to use when fetching the members
*/ */
public async getAllMembers(threadId: Snowflake) { public async getAllMembers(threadId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.threadMembers(threadId)) as Promise<RESTGetAPIChannelThreadMembersResult>; return this.rest.get(Routes.threadMembers(threadId), { signal }) as Promise<RESTGetAPIChannelThreadMembersResult>;
} }
} }

View File

@@ -1,4 +1,4 @@
import { makeURLSearchParams, type REST } from '@discordjs/rest'; import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest';
import { import {
Routes, Routes,
type RESTGetAPICurrentUserApplicationRoleConnectionResult, type RESTGetAPICurrentUserApplicationRoleConnectionResult,
@@ -26,29 +26,33 @@ export class UsersAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/user#get-user} * @see {@link https://discord.com/developers/docs/resources/user#get-user}
* @param userId - The id of the user to fetch * @param userId - The id of the user to fetch
* @param options - The options to use when fetching the user
*/ */
public async get(userId: Snowflake) { public async get(userId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.user(userId)) as Promise<RESTGetAPIUserResult>; return this.rest.get(Routes.user(userId), { signal }) as Promise<RESTGetAPIUserResult>;
} }
/** /**
* Returns the user object of the requester's account * Returns the user object of the requester's account
* *
* @see {@link https://discord.com/developers/docs/resources/user#get-current-user} * @see {@link https://discord.com/developers/docs/resources/user#get-current-user}
* @param options - The options to use when fetching the current user
*/ */
public async getCurrent() { public async getCurrent({ signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.user('@me')) as Promise<RESTGetAPICurrentUserResult>; return this.rest.get(Routes.user('@me'), { signal }) as Promise<RESTGetAPICurrentUserResult>;
} }
/** /**
* Returns a list of partial guild objects the current user is a member of * Returns a list of partial guild objects the current user is a member of
* *
* @see {@link https://discord.com/developers/docs/resources/user#get-current-user-guilds} * @see {@link https://discord.com/developers/docs/resources/user#get-current-user-guilds}
* @param options - The options to use when fetching the current user's guilds * @param query - The query options to use when fetching the current user's guilds
* @param options - The options to use when fetching the guilds
*/ */
public async getGuilds(options: RESTGetAPICurrentUserGuildsQuery = {}) { public async getGuilds(query: RESTGetAPICurrentUserGuildsQuery = {}, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.userGuilds(), { return this.rest.get(Routes.userGuilds(), {
query: makeURLSearchParams(options), query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPICurrentUserGuildsResult>; }) as Promise<RESTGetAPICurrentUserGuildsResult>;
} }
@@ -57,19 +61,21 @@ export class UsersAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/user#leave-guild} * @see {@link https://discord.com/developers/docs/resources/user#leave-guild}
* @param guildId - The id of the guild * @param guildId - The id of the guild
* @param options - The options for leaving the guild
*/ */
public async leaveGuild(guildId: Snowflake) { public async leaveGuild(guildId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.delete(Routes.userGuild(guildId)); await this.rest.delete(Routes.userGuild(guildId), { signal });
} }
/** /**
* Edits the current user * Edits the current user
* *
* @see {@link https://discord.com/developers/docs/resources/user#modify-current-user} * @see {@link https://discord.com/developers/docs/resources/user#modify-current-user}
* @param user - The new data for the current user * @param body - The new data for the current user
* @param options - The options for editing the user
*/ */
public async edit(user: RESTPatchAPICurrentUserJSONBody) { public async edit(body: RESTPatchAPICurrentUserJSONBody, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.patch(Routes.user('@me'), { body: user }) as Promise<RESTPatchAPICurrentUserResult>; return this.rest.patch(Routes.user('@me'), { body, signal }) as Promise<RESTPatchAPICurrentUserResult>;
} }
/** /**
@@ -77,9 +83,10 @@ export class UsersAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/user#get-current-user-guild-member} * @see {@link https://discord.com/developers/docs/resources/user#get-current-user-guild-member}
* @param guildId - The id of the guild * @param guildId - The id of the guild
* @param options - The options for fetching the guild member
*/ */
public async getGuildMember(guildId: Snowflake) { public async getGuildMember(guildId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.userGuildMember(guildId)) as Promise<RESTGetCurrentUserGuildMemberResult>; return this.rest.get(Routes.userGuildMember(guildId), { signal }) as Promise<RESTGetCurrentUserGuildMemberResult>;
} }
/** /**
@@ -87,13 +94,18 @@ export class UsersAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/guild#modify-current-member} * @see {@link https://discord.com/developers/docs/resources/guild#modify-current-member}
* @param guildId - The id of the guild * @param guildId - The id of the guild
* @param member - The new data for the guild member * @param body - The new data for the guild member
* @param reason - The reason for editing this guild member * @param options - The options for editing the guild member
*/ */
public async editGuildMember(guildId: Snowflake, member: RESTPatchAPIGuildMemberJSONBody = {}, reason?: string) { public async editCurrentGuildMember(
guildId: Snowflake,
body: RESTPatchAPIGuildMemberJSONBody = {},
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) {
return this.rest.patch(Routes.guildMember(guildId, '@me'), { return this.rest.patch(Routes.guildMember(guildId, '@me'), {
reason, reason,
body: member, body,
signal,
}) as Promise<RESTPatchAPIGuildMemberResult>; }) as Promise<RESTPatchAPIGuildMemberResult>;
} }
@@ -102,10 +114,12 @@ export class UsersAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/user#create-dm} * @see {@link https://discord.com/developers/docs/resources/user#create-dm}
* @param userId - The id of the user to open a DM channel with * @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) { public async createDM(userId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.post(Routes.userChannels(), { return this.rest.post(Routes.userChannels(), {
body: { recipient_id: userId }, body: { recipient_id: userId },
signal,
}) as Promise<RESTPostAPICurrentUserCreateDMChannelResult>; }) as Promise<RESTPostAPICurrentUserCreateDMChannelResult>;
} }
@@ -113,9 +127,10 @@ export class UsersAPI {
* Gets the current user's connections * Gets the current user's connections
* *
* @see {@link https://discord.com/developers/docs/resources/user#get-user-connections} * @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() { public async getConnections({ signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.userConnections()) as Promise<RESTGetAPICurrentUserConnectionsResult>; return this.rest.get(Routes.userConnections(), { signal }) as Promise<RESTGetAPICurrentUserConnectionsResult>;
} }
/** /**
@@ -123,11 +138,12 @@ export class UsersAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/user#get-user-application-role-connection} * @see {@link https://discord.com/developers/docs/resources/user#get-user-application-role-connection}
* @param applicationId - The id of the application * @param applicationId - The id of the application
* @param options - The options for fetching the role connections
*/ */
public async getApplicationRoleConnection(applicationId: Snowflake) { public async getApplicationRoleConnection(applicationId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get( return this.rest.get(Routes.userApplicationRoleConnection(applicationId), {
Routes.userApplicationRoleConnection(applicationId), signal,
) as Promise<RESTGetAPICurrentUserApplicationRoleConnectionResult>; }) as Promise<RESTGetAPICurrentUserApplicationRoleConnectionResult>;
} }
/** /**
@@ -135,14 +151,17 @@ export class UsersAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/user#update-user-application-role-connection} * @see {@link https://discord.com/developers/docs/resources/user#update-user-application-role-connection}
* @param applicationId - The id of the application * @param applicationId - The id of the application
* @param body - The data to use when updating the application role connection
* @param options - The options to use when updating the application role connection * @param options - The options to use when updating the application role connection
*/ */
public async updateApplicationRoleConnection( public async updateApplicationRoleConnection(
applicationId: Snowflake, applicationId: Snowflake,
options: RESTPutAPICurrentUserApplicationRoleConnectionJSONBody, body: RESTPutAPICurrentUserApplicationRoleConnectionJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.put(Routes.userApplicationRoleConnection(applicationId), { return this.rest.put(Routes.userApplicationRoleConnection(applicationId), {
body: options, body,
signal,
}) as Promise<RESTPutAPICurrentUserApplicationRoleConnectionResult>; }) as Promise<RESTPutAPICurrentUserApplicationRoleConnectionResult>;
} }
} }

View File

@@ -1,5 +1,5 @@
import type { REST } from '@discordjs/rest'; import type { RequestData, REST } from '@discordjs/rest';
import { Routes, type GetAPIVoiceRegionsResult } from 'discord-api-types/v10'; import { Routes, type RESTGetAPIVoiceRegionsResult } from 'discord-api-types/v10';
export class VoiceAPI { export class VoiceAPI {
public constructor(private readonly rest: REST) {} public constructor(private readonly rest: REST) {}
@@ -8,8 +8,9 @@ export class VoiceAPI {
* Fetches all voice regions * Fetches all voice regions
* *
* @see {@link https://discord.com/developers/docs/resources/voice#list-voice-regions} * @see {@link https://discord.com/developers/docs/resources/voice#list-voice-regions}
* @param options - The options to use when fetching the voice regions
*/ */
public async getVoiceRegions() { public async getVoiceRegions({ signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.voiceRegions()) as Promise<GetAPIVoiceRegionsResult>; return this.rest.get(Routes.voiceRegions(), { signal }) as Promise<RESTGetAPIVoiceRegionsResult>;
} }
} }

View File

@@ -1,6 +1,7 @@
import { makeURLSearchParams, type RawFile, type REST } from '@discordjs/rest'; import { makeURLSearchParams, type RequestData, type RawFile, type REST } from '@discordjs/rest';
import { Routes } from 'discord-api-types/v10';
import { import {
Routes, type RESTGetAPIWebhookWithTokenMessageQuery,
type RESTGetAPIChannelMessageResult, type RESTGetAPIChannelMessageResult,
type RESTGetAPIWebhookResult, type RESTGetAPIWebhookResult,
type RESTPatchAPIWebhookJSONBody, type RESTPatchAPIWebhookJSONBody,
@@ -27,9 +28,10 @@ export class WebhooksAPI {
* @see {@link https://discord.com/developers/docs/resources/webhook#get-webhook-with-token} * @see {@link https://discord.com/developers/docs/resources/webhook#get-webhook-with-token}
* @param id - The id of the webhook * @param id - The id of the webhook
* @param token - The token of the webhook * @param token - The token of the webhook
* @param options - The options to use when fetching the webhook
*/ */
public async get(id: Snowflake, token?: string) { public async get(id: Snowflake, token?: string, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.webhook(id, token)) as Promise<RESTGetAPIWebhookResult>; return this.rest.get(Routes.webhook(id, token), { signal }) as Promise<RESTGetAPIWebhookResult>;
} }
/** /**
@@ -37,13 +39,18 @@ export class WebhooksAPI {
* *
* @see {@link https://discord.com/developers/docs/resources/webhook#create-webhook} * @see {@link https://discord.com/developers/docs/resources/webhook#create-webhook}
* @param channelId - The id of the channel to create the webhook in * @param channelId - The id of the channel to create the webhook in
* @param data - The data to use when creating the webhook * @param body - The data to use when creating the webhook
* @param reason - The reason for creating the webhook * @param options - The options to use when creating the webhook
*/ */
public async create(channelId: Snowflake, data: RESTPostAPIChannelWebhookJSONBody, reason?: string) { public async create(
channelId: Snowflake,
body: RESTPostAPIChannelWebhookJSONBody,
{ reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {},
) {
return this.rest.post(Routes.channelWebhooks(channelId), { return this.rest.post(Routes.channelWebhooks(channelId), {
reason, reason,
body: data, body,
signal,
}) as Promise<RESTPostAPIWebhookWithTokenResult>; }) as Promise<RESTPostAPIWebhookWithTokenResult>;
} }
@@ -53,15 +60,19 @@ export class WebhooksAPI {
* @see {@link https://discord.com/developers/docs/resources/webhook#modify-webhook} * @see {@link https://discord.com/developers/docs/resources/webhook#modify-webhook}
* @see {@link https://discord.com/developers/docs/resources/webhook#modify-webhook-with-token} * @see {@link https://discord.com/developers/docs/resources/webhook#modify-webhook-with-token}
* @param id - The id of the webhook to edit * @param id - The id of the webhook to edit
* @param webhook - The new webhook data * @param body - The new webhook data
* @param options - The options to use when editing the webhook * @param options - The options to use when editing the webhook
*/ */
public async edit( public async edit(
id: Snowflake, id: Snowflake,
webhook: RESTPatchAPIWebhookJSONBody, body: RESTPatchAPIWebhookJSONBody,
{ token, reason }: { reason?: string; token?: string } = {}, { token, reason, signal }: Pick<RequestData, 'reason' | 'signal'> & { token?: string | undefined } = {},
) { ) {
return this.rest.patch(Routes.webhook(id, token), { reason, body: webhook }) as Promise<RESTPatchAPIWebhookResult>; return this.rest.patch(Routes.webhook(id, token), {
reason,
body,
signal,
}) as Promise<RESTPatchAPIWebhookResult>;
} }
/** /**
@@ -72,8 +83,11 @@ export class WebhooksAPI {
* @param id - The id of the webhook to delete * @param id - The id of the webhook to delete
* @param options - The options to use when deleting the webhook * @param options - The options to use when deleting the webhook
*/ */
public async delete(id: Snowflake, { token, reason }: { reason?: string; token?: string } = {}) { public async delete(
await this.rest.delete(Routes.webhook(id, token), { reason }); id: Snowflake,
{ token, reason, signal }: Pick<RequestData, 'reason' | 'signal'> & { token?: string | undefined } = {},
) {
await this.rest.delete(Routes.webhook(id, token), { reason, signal });
} }
/** /**
@@ -82,12 +96,14 @@ export class WebhooksAPI {
* @see {@link https://discord.com/developers/docs/resources/webhook#execute-webhook} * @see {@link https://discord.com/developers/docs/resources/webhook#execute-webhook}
* @param id - The id of the webhook * @param id - The id of the webhook
* @param token - The token of the webhook * @param token - The token of the webhook
* @param data - The data to use when executing the webhook * @param body - The data to use when executing the webhook
* @param options - The options to use when executing the webhook
*/ */
public async execute( public async execute(
id: Snowflake, id: Snowflake,
token: string, token: string,
data: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[]; wait: true }, body: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[]; wait: true },
{ signal }: Pick<RequestData, 'signal'>,
): Promise<RESTPostAPIWebhookWithTokenWaitResult>; ): Promise<RESTPostAPIWebhookWithTokenWaitResult>;
/** /**
@@ -96,12 +112,14 @@ export class WebhooksAPI {
* @see {@link https://discord.com/developers/docs/resources/webhook#execute-webhook} * @see {@link https://discord.com/developers/docs/resources/webhook#execute-webhook}
* @param id - The id of the webhook * @param id - The id of the webhook
* @param token - The token of the webhook * @param token - The token of the webhook
* @param data - The data to use when executing the webhook * @param body - The data to use when executing the webhook
* @param options - The options to use when executing the webhook
*/ */
public async execute( public async execute(
id: Snowflake, id: Snowflake,
token: string, token: string,
data: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[]; wait?: false }, body: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[]; wait?: false },
{ signal }: Pick<RequestData, 'signal'>,
): Promise<void>; ): Promise<void>;
/** /**
@@ -110,7 +128,8 @@ export class WebhooksAPI {
* @see {@link https://discord.com/developers/docs/resources/webhook#execute-webhook} * @see {@link https://discord.com/developers/docs/resources/webhook#execute-webhook}
* @param id - The id of the webhook * @param id - The id of the webhook
* @param token - The token of the webhook * @param token - The token of the webhook
* @param data - The data to use when executing the webhook * @param body - The data to use when executing the webhook
* @param options - The options to use when executing the webhook
*/ */
public async execute( public async execute(
id: Snowflake, id: Snowflake,
@@ -121,12 +140,14 @@ export class WebhooksAPI {
files, files,
...body ...body
}: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[] }, }: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.post(Routes.webhook(id, token), { return this.rest.post(Routes.webhook(id, token), {
query: makeURLSearchParams({ wait, thread_id }), query: makeURLSearchParams({ wait, thread_id }),
files, files,
body, body,
auth: false, auth: false,
signal,
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type // eslint-disable-next-line @typescript-eslint/no-invalid-void-type
}) as Promise<RESTPostAPIWebhookWithTokenWaitResult | void>; }) as Promise<RESTPostAPIWebhookWithTokenWaitResult | void>;
} }
@@ -137,18 +158,21 @@ export class WebhooksAPI {
* @see {@link https://discord.com/developers/docs/resources/webhook#execute-slackcompatible-webhook} * @see {@link https://discord.com/developers/docs/resources/webhook#execute-slackcompatible-webhook}
* @param id - The id of the webhook * @param id - The id of the webhook
* @param token - The token of the webhook * @param token - The token of the webhook
* @param query - The query options to use when executing the webhook
* @param options - The options to use when executing the webhook * @param options - The options to use when executing the webhook
*/ */
public async executeSlack( public async executeSlack(
id: Snowflake, id: Snowflake,
token: string, token: string,
body: unknown, body: unknown,
options: RESTPostAPIWebhookWithTokenSlackQuery = {}, query: RESTPostAPIWebhookWithTokenSlackQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
await this.rest.post(Routes.webhookPlatform(id, token, 'slack'), { await this.rest.post(Routes.webhookPlatform(id, token, 'slack'), {
query: makeURLSearchParams(options), query: makeURLSearchParams(query),
body, body,
auth: false, auth: false,
signal,
}); });
} }
@@ -158,17 +182,20 @@ export class WebhooksAPI {
* @see {@link https://discord.com/developers/docs/resources/webhook#execute-githubcompatible-webhook} * @see {@link https://discord.com/developers/docs/resources/webhook#execute-githubcompatible-webhook}
* @param id - The id of the webhook * @param id - The id of the webhook
* @param token - The token of the webhook * @param token - The token of the webhook
* @param query - The options to use when executing the webhook
* @param options - The options to use when executing the webhook * @param options - The options to use when executing the webhook
*/ */
public async executeGitHub( public async executeGitHub(
id: Snowflake, id: Snowflake,
token: string, token: string,
body: unknown, body: unknown,
options: RESTPostAPIWebhookWithTokenGitHubQuery = {}, query: RESTPostAPIWebhookWithTokenGitHubQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
await this.rest.post(Routes.webhookPlatform(id, token, 'github'), { await this.rest.post(Routes.webhookPlatform(id, token, 'github'), {
query: makeURLSearchParams(options), query: makeURLSearchParams(query),
body, body,
signal,
auth: false, auth: false,
}); });
} }
@@ -180,12 +207,20 @@ export class WebhooksAPI {
* @param id - The id of the webhook * @param id - The id of the webhook
* @param token - The token of the webhook * @param token - The token of the webhook
* @param messageId - The id of the message to fetch * @param messageId - The id of the message to fetch
* @param query - The query options to use when fetching the message
* @param options - The options to use when fetching the message * @param options - The options to use when fetching the message
*/ */
public async getMessage(id: Snowflake, token: string, messageId: Snowflake, options: { thread_id?: string } = {}) { public async getMessage(
id: Snowflake,
token: string,
messageId: Snowflake,
query: RESTGetAPIWebhookWithTokenMessageQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.webhookMessage(id, token, messageId), { return this.rest.get(Routes.webhookMessage(id, token, messageId), {
query: makeURLSearchParams(options), query: makeURLSearchParams(query),
auth: false, auth: false,
signal,
}) as Promise<RESTGetAPIChannelMessageResult>; }) as Promise<RESTGetAPIChannelMessageResult>;
} }
@@ -196,18 +231,21 @@ export class WebhooksAPI {
* @param id - The id of the webhook * @param id - The id of the webhook
* @param token - The token of the webhook * @param token - The token of the webhook
* @param messageId - The id of the message to edit * @param messageId - The id of the message to edit
* @param data - The data to use when editing the message * @param body - The data to use when editing the message
* @param options - The options to use when editing the message
*/ */
public async editMessage( public async editMessage(
id: Snowflake, id: Snowflake,
token: string, token: string,
messageId: Snowflake, messageId: Snowflake,
{ thread_id, ...body }: RESTPatchAPIWebhookWithTokenMessageJSONBody & { thread_id?: string }, { thread_id, ...body }: RESTPatchAPIWebhookWithTokenMessageJSONBody & { thread_id?: string },
{ signal }: Pick<RequestData, 'signal'> = {},
) { ) {
return this.rest.patch(Routes.webhookMessage(id, token, messageId), { return this.rest.patch(Routes.webhookMessage(id, token, messageId), {
query: makeURLSearchParams({ thread_id }), query: makeURLSearchParams({ thread_id }),
auth: false, auth: false,
body, body,
signal,
}) as Promise<RESTPatchAPIWebhookWithTokenMessageResult>; }) as Promise<RESTPatchAPIWebhookWithTokenMessageResult>;
} }
@@ -218,12 +256,20 @@ export class WebhooksAPI {
* @param id - The id of the webhook * @param id - The id of the webhook
* @param token - The token of the webhook * @param token - The token of the webhook
* @param messageId - The id of the message to delete * @param messageId - The id of the message to delete
* @param query - The options to use when deleting the message
* @param options - The options to use when deleting the message * @param options - The options to use when deleting the message
*/ */
public async deleteMessage(id: Snowflake, token: string, messageId: Snowflake, options: { thread_id?: string } = {}) { public async deleteMessage(
id: Snowflake,
token: string,
messageId: Snowflake,
query: { thread_id?: string } = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.delete(Routes.webhookMessage(id, token, messageId), { await this.rest.delete(Routes.webhookMessage(id, token, messageId), {
query: makeURLSearchParams(options), query: makeURLSearchParams(query),
auth: false, auth: false,
signal,
}); });
} }
} }