mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-09 16:13:31 +01:00
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 <github@almeidx.dev> * Apply suggestion from @almeidx Co-authored-by: Almeida <github@almeidx.dev> --------- Co-authored-by: Almeida <github@almeidx.dev>
This commit is contained in:
@@ -2,6 +2,7 @@ import { REST } from '@discordjs/rest';
|
|||||||
import type {
|
import type {
|
||||||
APIActionRowComponent,
|
APIActionRowComponent,
|
||||||
APIComponentInModalActionRow,
|
APIComponentInModalActionRow,
|
||||||
|
RESTGetAPIChannelThreadMemberResult,
|
||||||
RESTPostAPIInteractionCallbackWithResponseResult,
|
RESTPostAPIInteractionCallbackWithResponseResult,
|
||||||
} from 'discord-api-types/v10';
|
} from 'discord-api-types/v10';
|
||||||
import { expectTypeOf, describe, test } from 'vitest';
|
import { expectTypeOf, describe, test } from 'vitest';
|
||||||
@@ -158,3 +159,20 @@ describe('Interaction with_response overloads.', () => {
|
|||||||
Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>
|
Promise<RESTPostAPIInteractionCallbackWithResponseResult | undefined>
|
||||||
>());
|
>());
|
||||||
});
|
});
|
||||||
|
|
||||||
|
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<Required<Pick<RESTGetAPIChannelThreadMemberResult, 'member'>> & RESTGetAPIChannelThreadMemberResult>
|
||||||
|
>());
|
||||||
|
|
||||||
|
test('Getting a thread member without with_member returns RESTGetAPIChannelThreadMemberResult.', () => {
|
||||||
|
expectTypeOf(api.threads.getMember(SNOWFLAKE, SNOWFLAKE, { with_member: false })).toEqualTypeOf<
|
||||||
|
Promise<RESTGetAPIChannelThreadMemberResult>
|
||||||
|
>();
|
||||||
|
|
||||||
|
expectTypeOf(api.threads.getMember(SNOWFLAKE, SNOWFLAKE)).toEqualTypeOf<
|
||||||
|
Promise<RESTGetAPIChannelThreadMemberResult>
|
||||||
|
>();
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|||||||
@@ -1,9 +1,10 @@
|
|||||||
/* eslint-disable jsdoc/check-param-names */
|
/* eslint-disable jsdoc/check-param-names */
|
||||||
|
|
||||||
import type { RequestData, REST } from '@discordjs/rest';
|
import { makeURLSearchParams, type RequestData, type REST } from '@discordjs/rest';
|
||||||
import {
|
import {
|
||||||
Routes,
|
Routes,
|
||||||
type APIThreadMember,
|
type RESTGetAPIChannelThreadMemberQuery,
|
||||||
|
type RESTGetAPIChannelThreadMemberResult,
|
||||||
type RESTGetAPIChannelThreadMembersResult,
|
type RESTGetAPIChannelThreadMembersResult,
|
||||||
type Snowflake,
|
type Snowflake,
|
||||||
} from 'discord-api-types/v10';
|
} from 'discord-api-types/v10';
|
||||||
@@ -71,14 +72,43 @@ export class ThreadsAPI {
|
|||||||
* @see {@link https://discord.com/developers/docs/resources/channel#get-thread-member}
|
* @see {@link https://discord.com/developers/docs/resources/channel#get-thread-member}
|
||||||
* @param threadId - The id of the thread to fetch the member from
|
* @param threadId - The id of the thread to fetch the member from
|
||||||
* @param userId - The id of the user
|
* @param userId - The id of the user
|
||||||
|
* @param query - The query for fetching the member
|
||||||
* @param options - The options for fetching the member
|
* @param options - The options for fetching the member
|
||||||
*/
|
*/
|
||||||
public async getMember(
|
public async getMember(
|
||||||
threadId: Snowflake,
|
threadId: Snowflake,
|
||||||
userId: Snowflake,
|
userId: Snowflake,
|
||||||
|
query: RESTGetAPIChannelThreadMemberQuery & { with_member: true },
|
||||||
|
options?: Pick<RequestData, 'auth' | 'signal'>,
|
||||||
|
): Promise<Required<Pick<RESTGetAPIChannelThreadMemberResult, 'member'>> & 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<RequestData, 'auth' | 'signal'>,
|
||||||
|
): Promise<RESTGetAPIChannelThreadMemberResult>;
|
||||||
|
|
||||||
|
public async getMember(
|
||||||
|
threadId: Snowflake,
|
||||||
|
userId: Snowflake,
|
||||||
|
query: RESTGetAPIChannelThreadMemberQuery = {},
|
||||||
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
{ auth, signal }: Pick<RequestData, 'auth' | 'signal'> = {},
|
||||||
) {
|
) {
|
||||||
return this.rest.get(Routes.threadMembers(threadId, userId), { auth, signal }) as Promise<APIThreadMember>;
|
return this.rest.get(Routes.threadMembers(threadId, userId), {
|
||||||
|
auth,
|
||||||
|
signal,
|
||||||
|
query: makeURLSearchParams(query),
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user