Skip to content

Commit

Permalink
feat: add Client#getApplication() (#90)
Browse files Browse the repository at this point in the history
For the time being, we're preserving both methods – the /applications/@me route still doesn't have information about the team associated with the application unlike the /oauth2/applications/@me route.
  • Loading branch information
TTtie authored Jul 30, 2023
1 parent d462735 commit 5bc017e
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 2 deletions.
7 changes: 7 additions & 0 deletions index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1726,13 +1726,19 @@ declare namespace Dysnomia {
[key: string]: unknown;
}
interface OAuthApplicationInfo {
approximate_guild_count?: number;
bot_public: boolean;
bot_require_code_grant: boolean;
cover_image?: string;
custom_install_url?: string;
description: string;
flags?: number;
guild_id?: string;
// The docs say that there can be a partial guild object attached,
// but as of 2023-07-25, there is no guild object attached in either
// endpoints, so we cannot determine how partial the guild object really is.
// Proceed with caution.
guild?: unknown;
icon: string | null;
id: string;
install_params?: OAuthInstallParams;
Expand Down Expand Up @@ -2658,6 +2664,7 @@ declare namespace Dysnomia {
executeWebhook(webhookID: string, token: string, options: WebhookPayload): Promise<void>;
followChannel(channelID: string, webhookChannelID: string): Promise<ChannelFollow>;
getActiveGuildThreads(guildID: string): Promise<ListedGuildThreads>;
getApplication(): Promise<OAuthApplicationInfo>;
getArchivedThreads(channelID: string, type: "private", options?: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PrivateThreadChannel>>;
getArchivedThreads(channelID: string, type: "public", options?: GetArchivedThreadsOptions): Promise<ListedChannelThreads<PublicThreadChannel>>;
getAutoModerationRule(guildID: string, ruleID: string): Promise<AutoModerationRule>;
Expand Down
13 changes: 11 additions & 2 deletions lib/Client.js
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,15 @@ class Client extends EventEmitter {
});
}

/**
* Get data on the application associated with this bot account.
* The returned data is similar to the `getOAuthApplication()` method with additional information.
* @returns {Promise<Object>} The bot's application data. Refer to [Discord's Documentation](https://discord.com/developers/docs/resources/application#application-object) for object structure
*/
getApplication() {
return this.requestHandler.request("GET", Endpoints.APPLICATION, true);
}

/**
* Get all archived threads in a channel
* @arg {String} channelID The ID of the channel
Expand Down Expand Up @@ -2485,8 +2494,8 @@ class Client extends EventEmitter {
}

/**
* Get data on the bot's OAuth2 application
* @returns {Promise<Object>} The bot's application data. Refer to [Discord's Documentation](https://discord.com/developers/docs/topics/oauth2#get-current-application-information) for object structure
* Get data on the bot's OAuth2 application. See also `getApplication()` for more info.
* @returns {Promise<Object>} The bot's application data. Refer to [Discord's Documentation](https://discord.com/developers/docs/resources/application#application-object) for object structure
*/
getOAuthApplication() {
return this.requestHandler.request("GET", Endpoints.OAUTH2_APPLICATION, true);
Expand Down
1 change: 1 addition & 0 deletions lib/rest/Endpoints.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ module.exports.BASE_URL = "/api/v" + REST_VERSION;
module.exports.CDN_URL = "https://cdn.discordapp.com";
module.exports.CLIENT_URL = "https://discord.com";

module.exports.APPLICATION = "/applications/@me";
module.exports.AUTO_MODERATION_RULES = (guildID) => `/guilds/${guildID}/auto-moderation/rules`;
module.exports.AUTO_MODERATION_RULE = (guildID, ruleID) => `/guilds/${guildID}/auto-moderation/rules/${ruleID}`;
module.exports.ORIGINAL_INTERACTION_RESPONSE = (appID, interactToken) => `/webhooks/${appID}/${interactToken}`;
Expand Down

0 comments on commit 5bc017e

Please sign in to comment.