Skip to content

Commit

Permalink
Subject: [PATCH] feat(ClientApplication): Approximate guild count and…
Browse files Browse the repository at this point in the history
… new

 `GET` route (discordjs#9713)

Co-authored-by: Jiralite <33201955+Jiralite@users.noreply.github.com>
  • Loading branch information
jaw0r3k and Jiralite committed Aug 12, 2023
1 parent ec8f0d7 commit d3a7002
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/structures/ClientApplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ const Permissions = require('../util/Permissions');
*/

/**
* Represents a Client OAuth2 Application.
* Represents a client application.
* @extends {Application}
*/
class ClientApplication extends Application {
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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}
Expand All @@ -134,8 +163,8 @@ class ClientApplication extends Application {
* @returns {Promise<ClientApplication>}
*/
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;
}

Expand Down
3 changes: 3 additions & 0 deletions typings/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -676,11 +676,14 @@ export class Client<Ready extends boolean = boolean> 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<ApplicationFlags>;
public guildId: Snowflake | null;
public readonly guild: Guild | null;
public tags: string[];
public installParams: ClientApplicationInstallParams | null;
public customInstallURL: string | null;
Expand Down

0 comments on commit d3a7002

Please sign in to comment.