mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-11 00:53:31 +01:00
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:
@@ -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>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user