From 57ca3d7843605a944d41e82a0082aad20f15b669 Mon Sep 17 00:00:00 2001 From: Advaith Date: Wed, 12 Aug 2020 03:21:17 -0700 Subject: [PATCH] feat(Guild): updates for Community guilds (#4377) Co-authored-by: SpaceEEC --- src/client/Client.js | 2 +- src/structures/Guild.js | 72 ++++++++++++++++++++++++++++++---- src/structures/GuildPreview.js | 32 +++++++-------- typings/index.d.ts | 10 ++++- 4 files changed, 89 insertions(+), 27 deletions(-) diff --git a/src/client/Client.js b/src/client/Client.js index c7fcf2749..0ff8eb79f 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -341,7 +341,7 @@ class Client extends BaseClient { } /** - * Obtains a guild preview from Discord, only available for public guilds. + * Obtains a guild preview from Discord, available for all guilds the bot is in and all Discoverable guilds. * @param {GuildResolvable} guild The guild to fetch the preview for * @returns {Promise} */ diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 74da0205e..cd83f5a44 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -165,13 +165,12 @@ class Guild extends Base { * * ANIMATED_ICON * * BANNER * * COMMERCE + * * COMMUNITY * * DISCOVERABLE * * FEATURABLE * * INVITE_SPLASH * * NEWS * * PARTNERED - * * PUBLIC - * * PUBLIC_DISABLED * * VANITY_URL * * VERIFIED * * VIP_REGIONS @@ -368,18 +367,22 @@ class Guild extends Base { /** * The ID of the rules channel for the guild - * This is only available on guilds with the `PUBLIC` feature * @type {?Snowflake} */ this.rulesChannelID = data.rules_channel_id; /** - * The ID of the public updates channel for the guild - * This is only available on guilds with the `PUBLIC` feature + * The ID of the community updates channel for the guild * @type {?Snowflake} */ this.publicUpdatesChannelID = data.public_updates_channel_id; + /** + * The preferred locale of the guild, defaults to `en-US` + * @type {string} + */ + this.preferredLocale = data.preferred_locale; + if (data.channels) { this.channels.cache.clear(); for (const rawChannel of data.channels) { @@ -583,7 +586,6 @@ class Guild extends Base { /** * Rules channel for this guild - * This is only available on guilds with the `PUBLIC` feature * @type {?TextChannel} * @readonly */ @@ -593,7 +595,6 @@ class Guild extends Base { /** * Public updates channel for this guild - * This is only available on guilds with the `PUBLIC` feature * @type {?TextChannel} * @readonly */ @@ -766,7 +767,7 @@ class Guild extends Base { } /** - * Obtains a guild preview for this guild from Discord, only available for public guilds. + * Obtains a guild preview for this guild from Discord. * @returns {Promise} */ fetchPreview() { @@ -996,6 +997,9 @@ class Guild extends Base { * @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 + * @property {ChannelResolvable} [rulesChannel] The rules channel of the guild + * @property {ChannelResolvable} [publicUpdatesChannel] The community updates channel of the guild + * @property {string} [preferredLocale] The preferred locale of the guild */ /** @@ -1049,6 +1053,13 @@ class Guild extends Base { if (typeof data.systemChannelFlags !== 'undefined') { _data.system_channel_flags = SystemChannelFlags.resolve(data.systemChannelFlags); } + if (typeof data.rulesChannel !== 'undefined') { + _data.rules_channel_id = this.client.channels.resolveID(data.rulesChannel); + } + if (typeof data.publicUpdatesChannel !== 'undefined') { + _data.public_updates_channel_id = this.client.channels.resolveID(data.publicUpdatesChannel); + } + if (data.preferredLocale) _data.preferred_locale = data.preferredLocale; return this.client.api .guilds(this.id) .patch({ data: _data, reason }) @@ -1251,6 +1262,51 @@ class Guild extends Base { return this.edit({ banner: await DataResolver.resolveImage(banner), reason }); } + /** + * Edits the rules channel of the guild. + * @param {ChannelResolvable} rulesChannel The new rules channel + * @param {string} [reason] Reason for changing the guild's rules channel + * @returns {Promise} + * @example + * // Edit the guild rules channel + * guild.setRulesChannel(channel) + * .then(updated => console.log(`Updated guild rules channel to ${guild.rulesChannel.name}`)) + * .catch(console.error); + */ + setRulesChannel(rulesChannel, reason) { + return this.edit({ rulesChannel }, reason); + } + + /** + * Edits the community updates channel of the guild. + * @param {ChannelResolvable} publicUpdatesChannel The new community updates channel + * @param {string} [reason] Reason for changing the guild's community updates channel + * @returns {Promise} + * @example + * // Edit the guild community updates channel + * guild.setPublicUpdatesChannel(channel) + * .then(updated => console.log(`Updated guild community updates channel to ${guild.publicUpdatesChannel.name}`)) + * .catch(console.error); + */ + setPublicUpdatesChannel(publicUpdatesChannel, reason) { + return this.edit({ publicUpdatesChannel }, reason); + } + + /** + * Edits the preferred locale of the guild. + * @param {string} preferredLocale The new preferred locale of the guild + * @param {string} [reason] Reason for changing the guild's preferred locale + * @returns {Promise} + * @example + * // Edit the guild preferred locale + * guild.setPreferredLocale('en-US') + * .then(updated => console.log(`Updated guild preferred locale to ${guild.preferredLocale}`)) + * .catch(console.error); + */ + setPreferredLocale(preferredLocale, reason) { + return this.edit({ preferredLocale }, reason); + } + /** * The data needed for updating a channel's position. * @typedef {Object} ChannelPosition diff --git a/src/structures/GuildPreview.js b/src/structures/GuildPreview.js index 681ff607c..c2175d4e7 100644 --- a/src/structures/GuildPreview.js +++ b/src/structures/GuildPreview.js @@ -5,7 +5,7 @@ const GuildPreviewEmoji = require('./GuildPreviewEmoji'); const Collection = require('../util/Collection'); /** - * Represents the data about the guild any bot can preview, connected to the specified public guild. + * Represents the data about the guild any bot can preview, connected to the specified guild. * @extends {Base} */ class GuildPreview extends Base { @@ -18,37 +18,37 @@ class GuildPreview extends Base { } /** - * Builds the public guild with the provided data. - * @param {*} data The raw data of the public guild + * Builds the guild with the provided data. + * @param {*} data The raw data of the guild * @private */ _patch(data) { /** - * The id of this public guild + * The id of this guild * @type {string} */ this.id = data.id; /** - * The name of this public guild + * The name of this guild * @type {string} */ this.name = data.name; /** - * The icon of this public guild + * The icon of this guild * @type {?string} */ this.icon = data.icon; /** - * The splash icon of this public guild + * The splash icon of this guild * @type {?string} */ this.splash = data.splash; /** - * The discovery splash icon of this public guild + * The discovery splash icon of this guild * @type {?string} */ this.discoverySplash = data.discovery_splash; @@ -60,26 +60,26 @@ class GuildPreview extends Base { this.features = data.features; /** - * The approximate count of members in this public guild + * The approximate count of members in this guild * @type {number} */ this.approximateMemberCount = data.approximate_member_count; /** - * The approximate count of online members in this public guild + * The approximate count of online members in this guild * @type {number} */ this.approximatePresenceCount = data.approximate_presence_count; /** - * The description for this public guild + * The description for this guild * @type {?string} */ this.description = data.description; if (!this.emojis) { /** - * Collection of emojis belonging to this public guild + * Collection of emojis belonging to this guild * @type {Collection} */ this.emojis = new Collection(); @@ -92,7 +92,7 @@ class GuildPreview extends Base { } /** - * The URL to this public guild's splash. + * The URL to this guild's splash. * @param {ImageURLOptions} [options={}] Options for the Image URL * @returns {?string} */ @@ -102,7 +102,7 @@ class GuildPreview extends Base { } /** - * The URL to this public guild's discovery splash. + * The URL to this guild's discovery splash. * @param {ImageURLOptions} [options={}] Options for the Image URL * @returns {?string} */ @@ -112,7 +112,7 @@ class GuildPreview extends Base { } /** - * The URL to this public guild's icon. + * The URL to this guild's icon. * @param {ImageURLOptions} [options={}] Options for the Image URL * @returns {?string} */ @@ -122,7 +122,7 @@ class GuildPreview extends Base { } /** - * Fetches this public guild. + * Fetches this guild. * @returns {Promise} */ fetch() { diff --git a/typings/index.d.ts b/typings/index.d.ts index 078e00eb4..e8db4c25f 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -641,6 +641,7 @@ declare module 'discord.js' { public readonly owner: GuildMember | null; public ownerID: Snowflake; public readonly partnered: boolean; + public preferredLocale: string; public premiumSubscriptionCount: number | null; public premiumTier: PremiumTier; public presences: PresenceManager; @@ -702,8 +703,11 @@ declare module 'discord.js' { public setIcon(icon: Base64Resolvable | null, reason?: string): Promise; public setName(name: string, reason?: string): Promise; public setOwner(owner: GuildMemberResolvable, reason?: string): Promise; + public setPreferredLocale(preferredLocale: string, reason?: string): Promise; + public setPublicUpdatesChannel(publicUpdatesChannel: ChannelResolvable | null, reason?: string): Promise; public setRegion(region: string, reason?: string): Promise; public setRolePositions(rolePositions: RolePosition[]): Promise; + public setRulesChannel(rulesChannel: ChannelResolvable | null, reason?: string): Promise; public setSplash(splash: Base64Resolvable | null, reason?: string): Promise; public setSystemChannel(systemChannel: ChannelResolvable | null, reason?: string): Promise; public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise; @@ -2544,6 +2548,9 @@ declare module 'discord.js' { splash?: Base64Resolvable; discoverySplash?: Base64Resolvable; banner?: Base64Resolvable; + rulesChannel?: ChannelResolvable; + publicUpdatesChannel?: ChannelResolvable; + preferredLocale?: string; } interface GuildEmojiCreateOptions { @@ -2560,13 +2567,12 @@ declare module 'discord.js' { | 'ANIMATED_ICON' | 'BANNER' | 'COMMERCE' + | 'COMMUNITY' | 'DISCOVERABLE' | 'FEATURABLE' | 'INVITE_SPLASH' | 'NEWS' | 'PARTNERED' - | 'PUBLIC' - | 'PUBLIC_DISABLED' | 'VANITY_URL' | 'VERIFIED' | 'VIP_REGIONS'