From 632a9b4965cd24ffffdf0f88f1a9eedeb6b284f7 Mon Sep 17 00:00:00 2001 From: Jiralite <33201955+Jiralite@users.noreply.github.com> Date: Fri, 11 Aug 2023 08:11:13 +0100 Subject: [PATCH] feat(ClientApplication): Approximate guild count and new `GET` route (#9713) * feat: add approx guild count and get route * refactor: replace route * docs: update description of class The replacement route justifies this change. * feat(ClientApplication): add `approximateGuildCount` * refactor: revert now-unnecessary changes --- .../src/structures/ClientApplication.js | 35 +++++++++++++++++-- packages/discord.js/typings/index.d.ts | 3 ++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/packages/discord.js/src/structures/ClientApplication.js b/packages/discord.js/src/structures/ClientApplication.js index afee47d3c353..69f51340bb5d 100644 --- a/packages/discord.js/src/structures/ClientApplication.js +++ b/packages/discord.js/src/structures/ClientApplication.js @@ -15,7 +15,7 @@ const PermissionsBitField = require('../util/PermissionsBitField'); */ /** - * Represents a Client OAuth2 Application. + * Represents a client application. * @extends {Application} */ class ClientApplication extends Application { @@ -69,6 +69,26 @@ class ClientApplication extends Application { this.flags = new ApplicationFlagsBitField(data.flags).freeze(); } + if ('approximate_guild_count' in data) { + /** + * An approximate amount of guilds this application is in. + * @type {?number} + */ + this.approximateGuildCount = data.approximate_guild_count; + } else { + this.approximateGuildCount ??= null; + } + + if ('guild_id' in data) { + /** + * The id of the guild associated with this application. + * @type {?Snowflake} + */ + this.guildId = data.guild_id; + } else { + this.guildId ??= null; + } + if ('cover_image' in data) { /** * The hash of the application's cover image @@ -130,6 +150,15 @@ class ClientApplication extends Application { : this.owner ?? null; } + /** + * The guild associated with this application. + * @type {?Guild} + * @readonly + */ + get guild() { + return this.client.guilds.cache.get(this.guildId) ?? null; + } + /** * Whether this application is partial * @type {boolean} @@ -144,8 +173,8 @@ class ClientApplication extends Application { * @returns {Promise} */ async fetch() { - const app = await this.client.rest.get(Routes.oauth2CurrentApplication()); - this._patch(app); + const data = await this.client.rest.get(Routes.currentApplication()); + this._patch(data); return this; } diff --git a/packages/discord.js/typings/index.d.ts b/packages/discord.js/typings/index.d.ts index d5e9feee2558..21acbb14000a 100644 --- a/packages/discord.js/typings/index.d.ts +++ b/packages/discord.js/typings/index.d.ts @@ -1012,8 +1012,11 @@ export class ClientApplication extends Application { public botPublic: boolean | null; public botRequireCodeGrant: boolean | null; public commands: ApplicationCommandManager; + public guildId: Snowflake | null; + public get guild(): Guild | null; public cover: string | null; public flags: Readonly; + public approximateGuildCount: number | null; public tags: string[]; public installParams: ClientApplicationInstallParams | null; public customInstallURL: string | null;