From 5fbae157385656536a5490ea9c315aed9aa28189 Mon Sep 17 00:00:00 2001 From: Jaw0r3k Date: Sat, 12 Aug 2023 14:08:08 +0200 Subject: [PATCH] Subject: [PATCH] feat(ClientApplication): Approximate guild count and new `GET` route (#9713) Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com> --- src/structures/ClientApplication.js | 35 ++++++++++++++++++++++++++--- typings/index.d.ts | 3 +++ 2 files changed, 35 insertions(+), 3 deletions(-) diff --git a/src/structures/ClientApplication.js b/src/structures/ClientApplication.js index cae8b6d704b3..88095e9f1adf 100644 --- a/src/structures/ClientApplication.js +++ b/src/structures/ClientApplication.js @@ -15,7 +15,7 @@ const Permissions = require('../util/Permissions'); */ /** - * 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 ApplicationFlags(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 @@ -120,6 +140,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} @@ -134,8 +163,8 @@ class ClientApplication extends Application { * @returns {Promise} */ async fetch() { - const app = await this.client.api.oauth2.applications('@me').get(); - this._patch(app); + const data = await this.client.api.applications('@me').get(); + this._patch(data); return this; } diff --git a/typings/index.d.ts b/typings/index.d.ts index c18c0ef204c6..0bee446d6bdc 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -677,11 +677,14 @@ export class Client extends BaseClient { export class ClientApplication extends Application { private constructor(client: Client, data: RawClientApplicationData); + public approximateGuildCount: number | null; public botPublic: boolean | null; public botRequireCodeGrant: boolean | null; public commands: ApplicationCommandManager; public cover: string | null; public flags: Readonly; + public guildId: Snowflake | null; + public readonly guild: Guild | null; public tags: string[]; public installParams: ClientApplicationInstallParams | null; public customInstallURL: string | null;