From 5be6630843ef3c37b2f5090f9d3b13d26da3143e Mon Sep 17 00:00:00 2001 From: Advaith Date: Wed, 12 Aug 2020 02:09:18 -0700 Subject: [PATCH] feat(Guild): discovery splash (#4619) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: Antonio Román --- src/structures/Guild.js | 47 +++++++++++++++++++++++++++++++++++------ typings/index.d.ts | 4 ++++ 2 files changed, 45 insertions(+), 6 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 6730c9d6e..74da0205e 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -131,11 +131,17 @@ class Guild extends Base { this.icon = data.icon; /** - * The hash of the guild splash image (VIP only) + * The hash of the guild invite splash image * @type {?string} */ this.splash = data.splash; + /** + * The hash of the guild discovery splash image + * @type {?string} + */ + this.discoverySplash = data.discovery_splash; + /** * The region the guild is located in * @type {string} @@ -505,7 +511,7 @@ class Guild extends Base { } /** - * The URL to this guild's splash. + * The URL to this guild's invite splash image. * @param {ImageURLOptions} [options={}] Options for the Image URL * @returns {?string} */ @@ -514,6 +520,16 @@ class Guild extends Base { return this.client.rest.cdn.Splash(this.id, this.splash, format, size); } + /** + * The URL to this guild's discovery splash image. + * @param {ImageURLOptions} [options={}] Options for the Image URL + * @returns {?string} + */ + discoverySplashURL({ format, size } = {}) { + if (!this.discoverySplash) return null; + return this.client.rest.cdn.DiscoverySplash(this.id, this.discoverySplash, format, size); + } + /** * The owner of the guild * @type {?GuildMember} @@ -975,7 +991,8 @@ class Guild extends Base { * @property {number} [afkTimeout] The AFK timeout of the guild * @property {Base64Resolvable} [icon] The icon of the guild * @property {GuildMemberResolvable} [owner] The owner of the guild - * @property {Base64Resolvable} [splash] The splash screen of the guild + * @property {Base64Resolvable} [splash] The invite splash image of the guild + * @property {Base64Resolvable} [discoverySplash] The discovery splash image of the guild * @property {Base64Resolvable} [banner] The banner of the guild * @property {DefaultMessageNotifications|number} [defaultMessageNotifications] The default message notifications * @property {SystemChannelFlagsResolvable} [systemChannelFlags] The system channel flags of the guild @@ -1015,6 +1032,7 @@ class Guild extends Base { if (typeof data.icon !== 'undefined') _data.icon = data.icon; if (data.owner) _data.owner_id = this.client.users.resolveID(data.owner); if (data.splash) _data.splash = data.splash; + if (data.discoverySplash) _data.discovery_splash = data.discoverySplash; if (data.banner) _data.banner = data.banner; if (typeof data.explicitContentFilter !== 'undefined') { _data.explicit_content_filter = @@ -1190,9 +1208,9 @@ class Guild extends Base { } /** - * Sets a new guild splash screen. - * @param {Base64Resolvable|BufferResolvable} splash The new splash screen of the guild - * @param {string} [reason] Reason for changing the guild's splash screen + * Sets a new guild invite splash image. + * @param {Base64Resolvable|BufferResolvable} splash The new invite splash image of the guild + * @param {string} [reason] Reason for changing the guild's invite splash image * @returns {Promise} * @example * // Edit the guild splash @@ -1204,6 +1222,21 @@ class Guild extends Base { return this.edit({ splash: await DataResolver.resolveImage(splash), reason }); } + /** + * Sets a new guild discovery splash image. + * @param {Base64Resolvable|BufferResolvable} discoverySplash The new discovery splash image of the guild + * @param {string} [reason] Reason for changing the guild's discovery splash image + * @returns {Promise} + * @example + * // Edit the guild discovery splash + * guild.setDiscoverySplash('./discoverysplash.png') + * .then(updated => console.log('Updated the guild discovery splash')) + * .catch(console.error); + */ + async setDiscoverySplash(discoverySplash, reason) { + return this.edit({ discoverySplash: await DataResolver.resolveImage(discoverySplash), reason }); + } + /** * Sets a new guild banner. * @param {Base64Resolvable|BufferResolvable} banner The new banner of the guild @@ -1377,6 +1410,7 @@ class Guild extends Base { this.id === guild.id && this.available === guild.available && this.splash === guild.splash && + this.discoverySplash === guild.discoverySplash && this.region === guild.region && this.name === guild.name && this.memberCount === guild.memberCount && @@ -1421,6 +1455,7 @@ class Guild extends Base { }); json.iconURL = this.iconURL(); json.splashURL = this.splashURL(); + json.discoverySplashURL = this.discoverySplashURL(); json.bannerURL = this.bannerURL(); return json; } diff --git a/typings/index.d.ts b/typings/index.d.ts index 345888ea7..078e00eb4 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -618,6 +618,7 @@ declare module 'discord.js' { public defaultMessageNotifications: DefaultMessageNotifications | number; public deleted: boolean; public description: string | null; + public discoverySplash: string | null; public embedChannel: GuildChannel | null; public embedChannelID: Snowflake | null; public embedEnabled: boolean; @@ -668,6 +669,7 @@ declare module 'discord.js' { public bannerURL(options?: ImageURLOptions): string | null; public createIntegration(data: IntegrationData, reason?: string): Promise; public delete(): Promise; + public discoverySplashURL(options?: ImageURLOptions): string | null; public edit(data: GuildEditData, reason?: string): Promise; public equals(guild: Guild): boolean; public fetch(): Promise; @@ -694,6 +696,7 @@ declare module 'discord.js' { defaultMessageNotifications: DefaultMessageNotifications | number, reason?: string, ): Promise; + public setDiscoverySplash(discoverySplash: Base64Resolvable | null, reason?: string): Promise; public setEmbed(embed: GuildWidgetData, reason?: string): Promise; public setExplicitContentFilter(explicitContentFilter: ExplicitContentFilterLevel, reason?: string): Promise; public setIcon(icon: Base64Resolvable | null, reason?: string): Promise; @@ -2539,6 +2542,7 @@ declare module 'discord.js' { icon?: Base64Resolvable; owner?: GuildMemberResolvable; splash?: Base64Resolvable; + discoverySplash?: Base64Resolvable; banner?: Base64Resolvable; }