From 2c08b0f975b51e3b4aa6ad925ffcee75fd721a35 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Mon, 6 Oct 2025 10:35:31 +0100 Subject: [PATCH] feat(thread)!: Add query to getting a thread member (#11136) BREAKING CHANGE: Third parameter of `ThreadsAPI#getMember()` is now `query`, pushing `options` to the fourth. * feat(thread): add query to getting a thread member * Apply suggestion from @almeidx Co-authored-by: Almeida * Apply suggestion from @almeidx Co-authored-by: Almeida --------- Co-authored-by: Almeida --- packages/core/__tests__/types.test-d.ts | 18 +++++++++++++ packages/core/src/api/thread.ts | 36 ++++++++++++++++++++++--- 2 files changed, 51 insertions(+), 3 deletions(-) diff --git a/packages/core/__tests__/types.test-d.ts b/packages/core/__tests__/types.test-d.ts index 946e53f28..499d4798a 100644 --- a/packages/core/__tests__/types.test-d.ts +++ b/packages/core/__tests__/types.test-d.ts @@ -2,6 +2,7 @@ import { REST } from '@discordjs/rest'; import type { APIActionRowComponent, APIComponentInModalActionRow, + RESTGetAPIChannelThreadMemberResult, RESTPostAPIInteractionCallbackWithResponseResult, } from 'discord-api-types/v10'; import { expectTypeOf, describe, test } from 'vitest'; @@ -158,3 +159,20 @@ describe('Interaction with_response overloads.', () => { Promise >()); }); + +describe('Thread member overloads.', () => { + test('Getting a thread member with with_member makes the guild member present.', () => + expectTypeOf(api.threads.getMember(SNOWFLAKE, SNOWFLAKE, { with_member: true })).toEqualTypeOf< + Promise> & RESTGetAPIChannelThreadMemberResult> + >()); + + test('Getting a thread member without with_member returns RESTGetAPIChannelThreadMemberResult.', () => { + expectTypeOf(api.threads.getMember(SNOWFLAKE, SNOWFLAKE, { with_member: false })).toEqualTypeOf< + Promise + >(); + + expectTypeOf(api.threads.getMember(SNOWFLAKE, SNOWFLAKE)).toEqualTypeOf< + Promise + >(); + }); +}); diff --git a/packages/core/src/api/thread.ts b/packages/core/src/api/thread.ts index 8b77f0b31..b59366d32 100644 --- a/packages/core/src/api/thread.ts +++ b/packages/core/src/api/thread.ts @@ -1,9 +1,10 @@ /* eslint-disable jsdoc/check-param-names */ -import type { RequestData, REST } from '@discordjs/rest'; +import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest'; import { Routes, - type APIThreadMember, + type RESTGetAPIChannelThreadMemberQuery, + type RESTGetAPIChannelThreadMemberResult, type RESTGetAPIChannelThreadMembersResult, type Snowflake, } from 'discord-api-types/v10'; @@ -71,14 +72,43 @@ 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 query - The query for fetching the member * @param options - The options for fetching the member */ public async getMember( threadId: Snowflake, userId: Snowflake, + query: RESTGetAPIChannelThreadMemberQuery & { with_member: true }, + options?: Pick, + ): Promise> & RESTGetAPIChannelThreadMemberResult>; + + /** + * Fetches a member of a thread + * + * @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 query - The query for fetching the member + * @param options - The options for fetching the member + */ + public async getMember( + threadId: Snowflake, + userId: Snowflake, + query?: RESTGetAPIChannelThreadMemberQuery, + options?: Pick, + ): Promise; + + public async getMember( + threadId: Snowflake, + userId: Snowflake, + query: RESTGetAPIChannelThreadMemberQuery = {}, { auth, signal }: Pick = {}, ) { - return this.rest.get(Routes.threadMembers(threadId, userId), { auth, signal }) as Promise; + return this.rest.get(Routes.threadMembers(threadId, userId), { + auth, + signal, + query: makeURLSearchParams(query), + }); } /**