From 5cb9b76e6571e1ce344db5e7353b41196816ddb4 Mon Sep 17 00:00:00 2001 From: Fleny Date: Fri, 9 Feb 2024 19:45:27 +0100 Subject: [PATCH] fix(rest): Add support for getGuilds with bot token (#3360) * Add support for getGuilds with bot token * Update manager.ts * Fix prettier error --- packages/rest/src/manager.ts | 16 ++++++++++------ packages/rest/src/types.ts | 6 +++--- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/packages/rest/src/manager.ts b/packages/rest/src/manager.ts index 336e0bd76..53dc5404b 100644 --- a/packages/rest/src/manager.ts +++ b/packages/rest/src/manager.ts @@ -1098,12 +1098,16 @@ export function createRestManager(options: CreateRestManagerOptions): RestManage }, async getGuilds(token, options) { - return await rest.get(rest.routes.guilds.userGuilds(options), { - headers: { - authorization: `Bearer ${token}`, - }, - unauthorized: true, - }) + const makeRequestOptions: MakeRequestOptions | undefined = token + ? { + headers: { + authorization: `Bearer ${token}`, + }, + unauthorized: true, + } + : undefined + + return await rest.get(rest.routes.guilds.userGuilds(options), makeRequestOptions) }, async getGuildApplicationCommand(commandId, guildId) { diff --git a/packages/rest/src/types.ts b/packages/rest/src/types.ts index f33f6b342..cb4e51177 100644 --- a/packages/rest/src/types.ts +++ b/packages/rest/src/types.ts @@ -1794,16 +1794,16 @@ export interface RestManager { /** * Get the user guilds. * - * @param bearerToken - The access token of the user + * @param bearerToken - The access token of the user, if unspecified the bot token is used instead * @param options - The parameters for the fetching of the guild. * @returns An instance of {@link Guild}. * * @remarks - * The access tokens needs to have the `guilds` scope + * If used with an access token, the token needs to have the `guilds` scope * * @see {@link https://discord.com/developers/docs/resources/user#get-current-user-guilds} */ - getGuilds: (bearerToken: string, options?: GetUserGuilds) => Promise + getGuilds: (bearerToken?: string, options?: GetUserGuilds) => Promise /** * Gets a guild application command by its ID. *