From 8c2ababa786be470519e08846a1d843b406f9f50 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Wed, 21 Feb 2024 21:52:26 +0000 Subject: [PATCH] feat(guild): Add `with_counts` to getting guilds (#10143) * feat(guild): add get with counts * refactor: simplify `query` Co-authored-by: Almeida --------- Co-authored-by: Almeida --- packages/core/src/api/guild.ts | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/packages/core/src/api/guild.ts b/packages/core/src/api/guild.ts index fc5c6e461..f6a29b79c 100644 --- a/packages/core/src/api/guild.ts +++ b/packages/core/src/api/guild.ts @@ -26,6 +26,7 @@ import { type RESTGetAPIGuildPreviewResult, type RESTGetAPIGuildPruneCountQuery, type RESTGetAPIGuildPruneCountResult, + type RESTGetAPIGuildQuery, type RESTGetAPIGuildResult, type RESTGetAPIGuildRolesResult, type RESTGetAPIGuildScheduledEventQuery, @@ -109,9 +110,38 @@ export class GuildsAPI { * @see {@link https://discord.com/developers/docs/resources/guild#get-guild} * @param guildId - The id of the guild * @param options - The options for fetching the guild + * @deprecated Use the overload with a query instead. */ - public async get(guildId: Snowflake, { signal }: Pick = {}) { - return this.rest.get(Routes.guild(guildId), { signal }) as Promise; + public async get(guildId: Snowflake, { signal }?: Pick): Promise; + + /** + * Fetches a guild + * + * @see {@link https://discord.com/developers/docs/resources/guild#get-guild} + * @param guildId - The id of the guild + * @param query - The query options for fetching the guild + * @param options - The options for fetching the guild + */ + public async get( + guildId: Snowflake, + query?: RESTGetAPIGuildQuery, + options?: Pick, + ): Promise; + + public async get( + guildId: Snowflake, + queryOrOptions: Pick | RESTGetAPIGuildQuery = {}, + options: Pick = {}, + ) { + const requestData: RequestData = { + signal: ('signal' in queryOrOptions ? queryOrOptions : options).signal, + }; + + if ('with_counts' in queryOrOptions) { + requestData.query = makeURLSearchParams(queryOrOptions); + } + + return this.rest.get(Routes.guild(guildId), requestData) as Promise; } /**