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 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>;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user