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 {
Routes,
type RESTGetAPIApplicationCommandPermissionsResult,
@@ -26,11 +26,17 @@ export class ApplicationCommandsAPI {
*
* @see {@link https://discord.com/developers/docs/interactions/application-commands#get-global-application-commands}
* @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
*/
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), {
query: makeURLSearchParams(options),
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIApplicationCommandsResult>;
}
@@ -39,11 +45,17 @@ export class ApplicationCommandsAPI {
*
* @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 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), {
body: data,
body,
signal,
}) as Promise<RESTPostAPIApplicationCommandsResult>;
}
@@ -53,11 +65,16 @@ export class ApplicationCommandsAPI {
* @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 commandId - The command id to fetch
* @param options - The options to use when fetching the command
*/
public async getGlobalCommand(applicationId: Snowflake, commandId: Snowflake) {
return this.rest.get(
Routes.applicationCommand(applicationId, commandId),
) as Promise<RESTGetAPIApplicationCommandResult>;
public async getGlobalCommand(
applicationId: Snowflake,
commandId: Snowflake,
{ 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}
* @param applicationId - The application id of the command
* @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(
applicationId: Snowflake,
commandId: Snowflake,
data: RESTPatchAPIApplicationCommandJSONBody,
body: RESTPatchAPIApplicationCommandJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.patch(Routes.applicationCommand(applicationId, commandId), {
body: data,
body,
signal,
}) as Promise<RESTPatchAPIApplicationCommandResult>;
}
@@ -84,9 +104,14 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#delete-global-application-command}
* @param applicationId - The application id of the command
* @param commandId - The id of the command to delete
* @param options - The options for deleting a command
*/
public async deleteGlobalCommand(applicationId: Snowflake, commandId: Snowflake) {
await this.rest.delete(Routes.applicationCommand(applicationId, commandId));
public async deleteGlobalCommand(
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}
* @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), {
body: data,
body,
signal,
}) as Promise<RESTPutAPIApplicationCommandsResult>;
}
@@ -108,15 +139,18 @@ export class ApplicationCommandsAPI {
* @see {@link https://discord.com/developers/docs/interactions/application-commands#get-guild-application-commands}
* @param applicationId - The application 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(
applicationId: Snowflake,
guildId: Snowflake,
data: RESTGetAPIApplicationGuildCommandsQuery = {},
query: RESTGetAPIApplicationGuildCommandsQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.applicationGuildCommands(applicationId, guildId), {
query: makeURLSearchParams(data),
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIApplicationCommandsResult>;
}
@@ -126,15 +160,18 @@ export class ApplicationCommandsAPI {
* @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 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(
applicationId: Snowflake,
guildId: Snowflake,
data: RESTPostAPIApplicationCommandsJSONBody,
body: RESTPostAPIApplicationCommandsJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.applicationGuildCommands(applicationId, guildId), {
body: data,
body,
signal,
}) as Promise<RESTPostAPIApplicationCommandsResult>;
}
@@ -145,11 +182,17 @@ export class ApplicationCommandsAPI {
* @param applicationId - The application id to fetch the command from
* @param guildId - The guild id to fetch the command from
* @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) {
return this.rest.get(
Routes.applicationGuildCommand(applicationId, guildId, commandId),
) as Promise<RESTGetAPIApplicationCommandResult>;
public async getGuildCommand(
applicationId: Snowflake,
guildId: Snowflake,
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 guildId - The guild id of the command
* @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(
applicationId: Snowflake,
guildId: Snowflake,
commandId: Snowflake,
data: RESTPatchAPIApplicationCommandJSONBody,
body: RESTPatchAPIApplicationCommandJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.patch(Routes.applicationGuildCommand(applicationId, guildId, commandId), {
body: data,
body,
signal,
}) as Promise<RESTPatchAPIApplicationCommandResult>;
}
@@ -179,9 +225,15 @@ export class ApplicationCommandsAPI {
* @param applicationId - The application id of the command
* @param guildId - The guild id of the command
* @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) {
await this.rest.delete(Routes.applicationGuildCommand(applicationId, guildId, commandId));
public async deleteGuildCommand(
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}
* @param applicationId - The application 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(
applicationId: Snowflake,
guildId: Snowflake,
data: RESTPutAPIApplicationCommandsJSONBody,
body: RESTPutAPIApplicationCommandsJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.put(Routes.applicationGuildCommands(applicationId, guildId), {
body: data,
body,
signal,
}) as Promise<RESTPutAPIApplicationCommandsResult>;
}
@@ -209,11 +264,17 @@ export class ApplicationCommandsAPI {
* @param applicationId - The application id to get the permissions for
* @param guildId - The guild id of the command
* @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) {
return this.rest.get(
Routes.applicationCommandPermissions(applicationId, guildId, commandId),
) as Promise<RESTGetAPIApplicationCommandPermissionsResult>;
public async getGuildCommandPermissions(
applicationId: Snowflake,
guildId: Snowflake,
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}
* @param applicationId - The application 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) {
return this.rest.get(
Routes.guildApplicationCommandsPermissions(applicationId, guildId),
) as Promise<RESTGetAPIGuildApplicationCommandsPermissionsResult>;
public async getGuildCommandsPermissions(
applicationId: Snowflake,
guildId: Snowflake,
{ 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 guildId - The guild id 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(
userToken: string,
applicationId: Snowflake,
guildId: Snowflake,
commandId: Snowflake,
data: RESTPutAPIApplicationCommandPermissionsJSONBody,
body: RESTPutAPIApplicationCommandPermissionsJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.put(Routes.applicationCommandPermissions(applicationId, guildId, commandId), {
headers: { Authorization: `Bearer ${userToken.replace('Bearer ', '')}` },
auth: false,
body: data,
body,
signal,
}) 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 {
Routes,
type RESTDeleteAPIChannelResult,
@@ -33,15 +33,18 @@ export class ChannelsAPI {
*
* @see {@link https://discord.com/developers/docs/resources/channel#create-message}
* @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(
channelId: Snowflake,
{ files, ...body }: RESTPostAPIChannelMessageJSONBody & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.channelMessages(channelId), {
files,
body,
signal,
}) as Promise<RESTPostAPIChannelMessageResult>;
}
@@ -51,16 +54,19 @@ export class ChannelsAPI {
* @see {@link https://discord.com/developers/docs/resources/channel#edit-message}
* @param channelId - The id of the channel the message is in
* @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(
channelId: Snowflake,
messageId: Snowflake,
{ files, ...body }: RESTPostAPIChannelMessageJSONBody & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'>,
) {
return this.rest.patch(Routes.channelMessage(channelId, messageId), {
files,
body,
signal,
}) as Promise<RESTPatchAPIChannelMessageResult>;
}
@@ -71,16 +77,19 @@ export class ChannelsAPI {
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message 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(
channelId: Snowflake,
messageId: Snowflake,
emoji: string,
options: RESTGetAPIChannelMessageReactionUsersQuery = {},
query: RESTGetAPIChannelMessageReactionUsersQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.channelMessageReaction(channelId, messageId, encodeURIComponent(emoji)), {
query: makeURLSearchParams(options),
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIChannelMessageReactionUsersResult>;
}
@@ -91,9 +100,17 @@ export class ChannelsAPI {
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message 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) {
await this.rest.delete(Routes.channelMessageOwnReaction(channelId, messageId, encodeURIComponent(emoji)));
public async deleteOwnMessageReaction(
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 emoji - The emoji 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) {
await this.rest.delete(Routes.channelMessageUserReaction(channelId, messageId, encodeURIComponent(emoji), userId));
public async deleteUserMessageReaction(
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}
* @param channelId - The id of the channel the message is in
* @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) {
await this.rest.delete(Routes.channelMessageAllReactions(channelId, messageId));
public async deleteAllMessageReactions(
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 messageId - The id of the message 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) {
await this.rest.delete(Routes.channelMessageReaction(channelId, messageId, encodeURIComponent(emoji)));
public async deleteAllMessageReactionsForEmoji(
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 messageId - The id of the message to add the reaction to
* @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) {
await this.rest.put(Routes.channelMessageOwnReaction(channelId, messageId, encodeURIComponent(emoji)));
public async addMessageReaction(
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}
* @param channelId - The id of the channel
* @param options - The options for fetching the channel
*/
public async get(channelId: Snowflake) {
return this.rest.get(Routes.channel(channelId)) as Promise<RESTGetAPIChannelResult>;
public async get(channelId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @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) {
return this.rest.patch(Routes.channel(channelId), { body: data }) as Promise<RESTPatchAPIChannelResult>;
public async edit(
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}
* @param channelId - The id of the channel to delete
* @param options - The options for deleting the channel
*/
public async delete(channelId: Snowflake) {
return this.rest.delete(Routes.channel(channelId)) as Promise<RESTDeleteAPIChannelResult>;
public async delete(channelId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @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), {
query: makeURLSearchParams(options),
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIChannelMessagesResult>;
}
@@ -193,9 +249,10 @@ export class ChannelsAPI {
*
* @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 options - The options for showing the typing indicator
*/
public async showTyping(channelId: Snowflake) {
await this.rest.post(Routes.channelTyping(channelId));
public async showTyping(channelId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @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) {
return this.rest.get(Routes.channelPins(channelId)) as Promise<RESTGetAPIChannelPinsResult>;
public async getPins(channelId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @param channelId - The id of the channel to pin the message in
* @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) {
await this.rest.put(Routes.channelPin(channelId, messageId), { reason });
public async pinMessage(
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}
* @param channelId - The id of the channel the message is in
* @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) {
await this.rest.delete(Routes.channelMessage(channelId, messageId), { reason });
public async deleteMessage(
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}
* @param channelId - The id of the channel the messages are in
* @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> {
await this.rest.post(Routes.channelBulkDelete(channelId), { reason, body: { messages: messageIds } });
public async bulkDeleteMessages(
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}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to fetch
* @param options - The options for fetching the message
*/
public async getMessage(channelId: Snowflake, messageId: Snowflake) {
return this.rest.get(Routes.channelMessage(channelId, messageId)) as Promise<RESTGetAPIChannelMessageResult>;
public async getMessage(channelId: Snowflake, messageId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @param channelId - The id of the channel the message is in
* @param messageId - The id of the message to crosspost
* @param options - The options for crossposting the message
*/
public async crosspostMessage(channelId: Snowflake, messageId: Snowflake) {
return this.rest.post(
Routes.channelMessageCrosspost(channelId, messageId),
) as Promise<RESTPostAPIChannelMessageCrosspostResult>;
public async crosspostMessage(
channelId: Snowflake,
messageId: Snowflake,
{ 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}
* @param channelId - The id of the channel to unpin the message in
* @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) {
await this.rest.delete(Routes.channelPin(channelId, messageId), { reason });
public async unpinMessage(
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}
* @param channelId - The id of the announcement channel to follow
* @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), {
body: { webhook_channel_id: webhookChannelId },
signal,
}) as Promise<RESTPostAPIChannelFollowersResult>;
}
@@ -297,12 +386,18 @@ export class ChannelsAPI {
*
* @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 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), {
reason,
body: data,
body,
signal,
}) as Promise<RESTPostAPIChannelInviteResult>;
}
@@ -311,9 +406,10 @@ export class ChannelsAPI {
*
* @see {@link https://discord.com/developers/docs/resources/channel#get-channel-invites}
* @param channelId - The id of the channel to fetch invites from
* @param options - The options for fetching the invites
*/
public async getInvites(channelId: Snowflake) {
return this.rest.get(Routes.channelInvites(channelId)) as Promise<RESTGetAPIChannelInvitesResult>;
public async getInvites(channelId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @param channelId - The id of the channel to fetch archived threads from
* @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(
channelId: Snowflake,
archivedStatus: 'private' | 'public',
options: RESTGetAPIChannelThreadsArchivedQuery = {},
query: RESTGetAPIChannelThreadsArchivedQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.channelThreads(channelId, archivedStatus), {
query: makeURLSearchParams(options),
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIChannelUsersThreadsArchivedResult>;
}
@@ -340,14 +439,17 @@ export class ChannelsAPI {
*
* @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 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(
channelId: Snowflake,
options: RESTGetAPIChannelThreadsArchivedQuery = {},
query: RESTGetAPIChannelThreadsArchivedQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.get(Routes.channelJoinedArchivedThreads(channelId), {
query: makeURLSearchParams(options),
query: makeURLSearchParams(query),
signal,
}) 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 type {
Snowflake,
APICommandAutocompleteInteractionResponseCallbackData,
APIInteractionResponseCallbackData,
APIModalInteractionResponseCallbackData,
RESTGetAPIWebhookWithTokenMessageResult,
Snowflake,
} from 'discord-api-types/v10';
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}
* @param interactionId - The id 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(
interactionId: Snowflake,
interactionToken: string,
{ files, ...data }: APIInteractionResponseCallbackData & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
files,
@@ -32,6 +34,7 @@ export class InteractionsAPI {
type: InteractionResponseType.ChannelMessageWithSource,
data,
},
signal,
});
}
@@ -41,13 +44,15 @@ export class InteractionsAPI {
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response}
* @param interactionId - The id 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), {
auth: false,
body: {
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}
* @param interactionId - The id 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), {
auth: false,
body: {
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}
* @param applicationId - The application id 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(
applicationId: Snowflake,
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}
* @param applicationId - The application id 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 options - The options to use when editing the reply
*/
public async editReply(
applicationId: Snowflake,
interactionToken: string,
data: APIInteractionResponseCallbackData & { files?: RawFile[] },
callbackData: APIInteractionResponseCallbackData & { files?: RawFile[] },
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}
* @param applicationId - The application id 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(
applicationId,
interactionToken,
'@original',
{},
{ signal },
) as Promise<RESTGetAPIWebhookWithTokenMessageResult>;
}
@@ -125,9 +149,15 @@ export class InteractionsAPI {
* @param applicationId - The application id 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 options - The options to use when deleting the reply
*/
public async deleteReply(applicationId: Snowflake, interactionToken: string, messageId?: Snowflake | '@original') {
await this.webhooks.deleteMessage(applicationId, interactionToken, messageId ?? '@original');
public async deleteReply(
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}
* @param interactionId - The id 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(
interactionId: Snowflake,
interactionToken: string,
{ files, ...data }: APIInteractionResponseCallbackData & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
files,
@@ -150,6 +182,7 @@ export class InteractionsAPI {
type: InteractionResponseType.UpdateMessage,
data,
},
signal,
});
}
@@ -159,19 +192,22 @@ export class InteractionsAPI {
* @see {@link https://discord.com/developers/docs/interactions/receiving-and-responding#create-interaction-response}
* @param interactionId - The id 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(
interactionId: Snowflake,
interactionToken: string,
data: APICommandAutocompleteInteractionResponseCallbackData,
callbackData: APICommandAutocompleteInteractionResponseCallbackData,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
auth: false,
body: {
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}
* @param interactionId - The id 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(
interactionId: Snowflake,
interactionToken: string,
data: APIModalInteractionResponseCallbackData,
callbackData: APIModalInteractionResponseCallbackData,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.post(Routes.interactionCallback(interactionId, interactionToken), {
auth: false,
body: {
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';
export class InvitesAPI {
@@ -9,10 +9,13 @@ export class InvitesAPI {
*
* @see {@link https://discord.com/developers/docs/resources/invite#get-invite}
* @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), {
query: makeURLSearchParams(options),
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPIInviteResult>;
}
@@ -21,9 +24,9 @@ export class InvitesAPI {
*
* @see {@link https://discord.com/developers/docs/resources/invite#delete-invite}
* @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) {
await this.rest.delete(Routes.invite(code), { reason });
public async delete(code: string, { reason, signal }: Pick<RequestData, 'reason' | 'signal'> = {}) {
await this.rest.delete(Routes.invite(code), { reason, signal });
}
}

View File

@@ -1,6 +1,5 @@
import { URL } from 'node:url';
import type { REST } from '@discordjs/rest';
import { makeURLSearchParams } from '@discordjs/rest';
import { type RequestData, type REST, makeURLSearchParams } from '@discordjs/rest';
import {
Routes,
RouteBases,
@@ -34,15 +33,20 @@ export class OAuth2API {
* 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}
* @param body - The body of 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(), {
body: makeURLSearchParams(options),
body: makeURLSearchParams(body),
passThroughBody: true,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
signal,
}) as Promise<RESTPostOAuth2AccessTokenResult>;
}
@@ -50,15 +54,20 @@ export class OAuth2API {
* 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}
* @param body - 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(), {
body: makeURLSearchParams(options),
body: makeURLSearchParams(body),
passThroughBody: true,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
signal,
}) as Promise<RESTPostOAuth2RefreshTokenResult>;
}
@@ -68,15 +77,20 @@ export class OAuth2API {
* @remarks
* This is primarily used for testing purposes
* @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
*/
public async getToken(options: RESTPostOAuth2ClientCredentialsURLEncodedData) {
public async getToken(
body: RESTPostOAuth2ClientCredentialsURLEncodedData,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.oauth2TokenExchange(), {
body: makeURLSearchParams(options),
body: makeURLSearchParams(body),
passThroughBody: true,
headers: {
'Content-Type': 'application/x-www-form-urlencoded',
},
signal,
}) as Promise<RESTPostOAuth2ClientCredentialsResult>;
}
@@ -84,17 +98,23 @@ export class OAuth2API {
* Fetches the current bot's 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() {
return this.rest.get(Routes.oauth2CurrentApplication()) as Promise<RESTGetAPIOAuth2CurrentApplicationResult>;
public async getCurrentBotApplicationInformation({ signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.oauth2CurrentApplication(), {
signal,
}) as Promise<RESTGetAPIOAuth2CurrentApplicationResult>;
}
/**
* Fetches the 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() {
return this.rest.get(Routes.oauth2CurrentAuthorization()) as Promise<RESTGetAPIOAuth2CurrentAuthorizationResult>;
public async getCurrentAuthorizationInformation({ signal }: Pick<RequestData, 'signal'> = {}) {
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 {
Routes,
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}
* @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) {
return this.rest.get(
Routes.applicationRoleConnectionMetadata(applicationId),
) as Promise<RESTGetAPIApplicationRoleConnectionMetadataResult>;
public async getMetadataRecords(applicationId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.applicationRoleConnectionMetadata(applicationId), {
signal,
}) 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}
* @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(
applicationId: Snowflake,
options: RESTPutAPIApplicationCommandPermissionsJSONBody,
body: RESTPutAPIApplicationCommandPermissionsJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.put(Routes.applicationRoleConnectionMetadata(applicationId), {
body: options,
body,
signal,
}) as Promise<RESTPutAPIApplicationRoleConnectionMetadataResult>;
}
}

View File

@@ -1,4 +1,4 @@
import type { REST } from '@discordjs/rest';
import type { RequestData, REST } from '@discordjs/rest';
import {
Routes,
type RESTGetAPIStickerResult,
@@ -13,9 +13,10 @@ export class StickersAPI {
* Fetches all of the 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() {
return this.rest.get(Routes.nitroStickerPacks()) as Promise<RESTGetNitroStickerPacksResult>;
public async getNitroStickers({ signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @param stickerId - The id of the sticker
* @param options - The options to use when fetching the sticker
*/
public async get(stickerId: Snowflake) {
return this.rest.get(Routes.sticker(stickerId)) as Promise<RESTGetAPIStickerResult>;
public async get(stickerId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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 {
Routes,
type APIThreadChannel,
@@ -10,10 +10,6 @@ import {
type Snowflake,
} from 'discord-api-types/v10';
export interface StartThreadOptions extends RESTPostAPIChannelThreadsJSONBody {
message_id?: string;
}
export interface StartForumThreadOptions extends RESTPostAPIGuildForumThreadsJSONBody {
message: RESTPostAPIGuildForumThreadsJSONBody['message'] & { files?: RawFile[] };
}
@@ -26,9 +22,10 @@ export class ThreadsAPI {
*
* @see {@link https://discord.com/developers/docs/resources/channel#get-channel}
* @param threadId - The id of the thread
* @param options - The options to use when fetching the thread
*/
public async get(threadId: Snowflake) {
return this.rest.get(Routes.channel(threadId)) as Promise<APIThreadChannel>;
public async get(threadId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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-without-message}
* @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) {
return this.rest.post(Routes.threads(channelId, message_id), { body }) as Promise<RESTPostAPIChannelThreadsResult>;
public async create(
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}
* @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 body = {
@@ -58,7 +70,7 @@ export class ThreadsAPI {
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}
* @param threadId - The id of the thread to join
* @param options - The options to use when joining the thread
*/
public async join(threadId: Snowflake) {
await this.rest.put(Routes.threadMembers(threadId, '@me'));
public async join(threadId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @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 options - The options to use when adding the member to the thread
*/
public async addMember(threadId: Snowflake, userId: Snowflake) {
await this.rest.put(Routes.threadMembers(threadId, userId));
public async addMember(threadId: Snowflake, userId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @param threadId - The id of the thread to leave
* @param options - The options to use when leaving the thread
*/
public async leave(threadId: Snowflake) {
await this.rest.delete(Routes.threadMembers(threadId, '@me'));
public async leave(threadId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @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 options - The options to use when removing the member from the thread
*/
public async removeMember(threadId: Snowflake, userId: Snowflake) {
await this.rest.delete(Routes.threadMembers(threadId, userId));
public async removeMember(threadId: Snowflake, userId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @param threadId - The id of the thread to fetch the member from
* @param userId - The id of the user
* @param options - The options to use when fetching the member
*/
public async getMember(threadId: Snowflake, userId: Snowflake) {
return this.rest.get(Routes.threadMembers(threadId, userId)) as Promise<APIThreadMember>;
public async getMember(threadId: Snowflake, userId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @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) {
return this.rest.get(Routes.threadMembers(threadId)) as Promise<RESTGetAPIChannelThreadMembersResult>;
public async getAllMembers(threadId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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 {
Routes,
type RESTGetAPICurrentUserApplicationRoleConnectionResult,
@@ -26,29 +26,33 @@ export class UsersAPI {
*
* @see {@link https://discord.com/developers/docs/resources/user#get-user}
* @param userId - The id of the user to fetch
* @param options - The options to use when fetching the user
*/
public async get(userId: Snowflake) {
return this.rest.get(Routes.user(userId)) as Promise<RESTGetAPIUserResult>;
public async get(userId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.user(userId), { signal }) as Promise<RESTGetAPIUserResult>;
}
/**
* Returns the user object of the requester's account
*
* @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() {
return this.rest.get(Routes.user('@me')) as Promise<RESTGetAPICurrentUserResult>;
public async getCurrent({ signal }: Pick<RequestData, 'signal'> = {}) {
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
*
* @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(), {
query: makeURLSearchParams(options),
query: makeURLSearchParams(query),
signal,
}) as Promise<RESTGetAPICurrentUserGuildsResult>;
}
@@ -57,19 +61,21 @@ export class UsersAPI {
*
* @see {@link https://discord.com/developers/docs/resources/user#leave-guild}
* @param guildId - The id of the guild
* @param options - The options for leaving the guild
*/
public async leaveGuild(guildId: Snowflake) {
await this.rest.delete(Routes.userGuild(guildId));
public async leaveGuild(guildId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
await this.rest.delete(Routes.userGuild(guildId), { signal });
}
/**
* Edits the 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) {
return this.rest.patch(Routes.user('@me'), { body: user }) as Promise<RESTPatchAPICurrentUserResult>;
public async edit(body: RESTPatchAPICurrentUserJSONBody, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @param guildId - The id of the guild
* @param options - The options for fetching the guild member
*/
public async getGuildMember(guildId: Snowflake) {
return this.rest.get(Routes.userGuildMember(guildId)) as Promise<RESTGetCurrentUserGuildMemberResult>;
public async getGuildMember(guildId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @param guildId - The id of the guild
* @param member - The new data for the guild member
* @param reason - The reason for editing this guild member
* @param body - The new data for the 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'), {
reason,
body: member,
body,
signal,
}) as Promise<RESTPatchAPIGuildMemberResult>;
}
@@ -102,10 +114,12 @@ export class UsersAPI {
*
* @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 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(), {
body: { recipient_id: userId },
signal,
}) as Promise<RESTPostAPICurrentUserCreateDMChannelResult>;
}
@@ -113,9 +127,10 @@ export class UsersAPI {
* Gets the current user's 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() {
return this.rest.get(Routes.userConnections()) as Promise<RESTGetAPICurrentUserConnectionsResult>;
public async getConnections({ signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @param applicationId - The id of the application
* @param options - The options for fetching the role connections
*/
public async getApplicationRoleConnection(applicationId: Snowflake) {
return this.rest.get(
Routes.userApplicationRoleConnection(applicationId),
) as Promise<RESTGetAPICurrentUserApplicationRoleConnectionResult>;
public async getApplicationRoleConnection(applicationId: Snowflake, { signal }: Pick<RequestData, 'signal'> = {}) {
return this.rest.get(Routes.userApplicationRoleConnection(applicationId), {
signal,
}) as Promise<RESTGetAPICurrentUserApplicationRoleConnectionResult>;
}
/**
@@ -135,14 +151,17 @@ export class UsersAPI {
*
* @see {@link https://discord.com/developers/docs/resources/user#update-user-application-role-connection}
* @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
*/
public async updateApplicationRoleConnection(
applicationId: Snowflake,
options: RESTPutAPICurrentUserApplicationRoleConnectionJSONBody,
body: RESTPutAPICurrentUserApplicationRoleConnectionJSONBody,
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.put(Routes.userApplicationRoleConnection(applicationId), {
body: options,
body,
signal,
}) as Promise<RESTPutAPICurrentUserApplicationRoleConnectionResult>;
}
}

View File

@@ -1,5 +1,5 @@
import type { REST } from '@discordjs/rest';
import { Routes, type GetAPIVoiceRegionsResult } from 'discord-api-types/v10';
import type { RequestData, REST } from '@discordjs/rest';
import { Routes, type RESTGetAPIVoiceRegionsResult } from 'discord-api-types/v10';
export class VoiceAPI {
public constructor(private readonly rest: REST) {}
@@ -8,8 +8,9 @@ export class VoiceAPI {
* Fetches all 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() {
return this.rest.get(Routes.voiceRegions()) as Promise<GetAPIVoiceRegionsResult>;
public async getVoiceRegions({ signal }: Pick<RequestData, 'signal'> = {}) {
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 {
Routes,
type RESTGetAPIWebhookWithTokenMessageQuery,
type RESTGetAPIChannelMessageResult,
type RESTGetAPIWebhookResult,
type RESTPatchAPIWebhookJSONBody,
@@ -27,9 +28,10 @@ export class WebhooksAPI {
* @see {@link https://discord.com/developers/docs/resources/webhook#get-webhook-with-token}
* @param id - The id 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) {
return this.rest.get(Routes.webhook(id, token)) as Promise<RESTGetAPIWebhookResult>;
public async get(id: Snowflake, token?: string, { signal }: Pick<RequestData, 'signal'> = {}) {
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}
* @param channelId - The id of the channel to create the webhook in
* @param data - The data to use when creating the webhook
* @param reason - The reason for creating the webhook
* @param body - The data to use when 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), {
reason,
body: data,
body,
signal,
}) 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-with-token}
* @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
*/
public async edit(
id: Snowflake,
webhook: RESTPatchAPIWebhookJSONBody,
{ token, reason }: { reason?: string; token?: string } = {},
body: RESTPatchAPIWebhookJSONBody,
{ 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 options - The options to use when deleting the webhook
*/
public async delete(id: Snowflake, { token, reason }: { reason?: string; token?: string } = {}) {
await this.rest.delete(Routes.webhook(id, token), { reason });
public async delete(
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}
* @param id - The id 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(
id: Snowflake,
token: string,
data: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[]; wait: true },
body: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[]; wait: true },
{ signal }: Pick<RequestData, 'signal'>,
): Promise<RESTPostAPIWebhookWithTokenWaitResult>;
/**
@@ -96,12 +112,14 @@ export class WebhooksAPI {
* @see {@link https://discord.com/developers/docs/resources/webhook#execute-webhook}
* @param id - The id 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(
id: Snowflake,
token: string,
data: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[]; wait?: false },
body: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[]; wait?: false },
{ signal }: Pick<RequestData, 'signal'>,
): Promise<void>;
/**
@@ -110,7 +128,8 @@ export class WebhooksAPI {
* @see {@link https://discord.com/developers/docs/resources/webhook#execute-webhook}
* @param id - The id 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(
id: Snowflake,
@@ -121,12 +140,14 @@ export class WebhooksAPI {
files,
...body
}: RESTPostAPIWebhookWithTokenJSONBody & RESTPostAPIWebhookWithTokenQuery & { files?: RawFile[] },
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.post(Routes.webhook(id, token), {
query: makeURLSearchParams({ wait, thread_id }),
files,
body,
auth: false,
signal,
// eslint-disable-next-line @typescript-eslint/no-invalid-void-type
}) as Promise<RESTPostAPIWebhookWithTokenWaitResult | void>;
}
@@ -137,18 +158,21 @@ export class WebhooksAPI {
* @see {@link https://discord.com/developers/docs/resources/webhook#execute-slackcompatible-webhook}
* @param id - The id 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
*/
public async executeSlack(
id: Snowflake,
token: string,
body: unknown,
options: RESTPostAPIWebhookWithTokenSlackQuery = {},
query: RESTPostAPIWebhookWithTokenSlackQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.post(Routes.webhookPlatform(id, token, 'slack'), {
query: makeURLSearchParams(options),
query: makeURLSearchParams(query),
body,
auth: false,
signal,
});
}
@@ -158,17 +182,20 @@ export class WebhooksAPI {
* @see {@link https://discord.com/developers/docs/resources/webhook#execute-githubcompatible-webhook}
* @param id - The id 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
*/
public async executeGitHub(
id: Snowflake,
token: string,
body: unknown,
options: RESTPostAPIWebhookWithTokenGitHubQuery = {},
query: RESTPostAPIWebhookWithTokenGitHubQuery = {},
{ signal }: Pick<RequestData, 'signal'> = {},
) {
await this.rest.post(Routes.webhookPlatform(id, token, 'github'), {
query: makeURLSearchParams(options),
query: makeURLSearchParams(query),
body,
signal,
auth: false,
});
}
@@ -180,12 +207,20 @@ export class WebhooksAPI {
* @param id - The id of the webhook
* @param token - The token of the webhook
* @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
*/
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), {
query: makeURLSearchParams(options),
query: makeURLSearchParams(query),
auth: false,
signal,
}) as Promise<RESTGetAPIChannelMessageResult>;
}
@@ -196,18 +231,21 @@ export class WebhooksAPI {
* @param id - The id of the webhook
* @param token - The token of the webhook
* @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(
id: Snowflake,
token: string,
messageId: Snowflake,
{ thread_id, ...body }: RESTPatchAPIWebhookWithTokenMessageJSONBody & { thread_id?: string },
{ signal }: Pick<RequestData, 'signal'> = {},
) {
return this.rest.patch(Routes.webhookMessage(id, token, messageId), {
query: makeURLSearchParams({ thread_id }),
auth: false,
body,
signal,
}) as Promise<RESTPatchAPIWebhookWithTokenMessageResult>;
}
@@ -218,12 +256,20 @@ export class WebhooksAPI {
* @param id - The id of the webhook
* @param token - The token of the webhook
* @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
*/
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), {
query: makeURLSearchParams(options),
query: makeURLSearchParams(query),
auth: false,
signal,
});
}
}