feat(Guild): updates for Community guilds (#4377)

Co-authored-by: SpaceEEC <spaceeec@users.noreply.github.com>
This commit is contained in:
Advaith
2020-08-12 03:21:17 -07:00
committed by GitHub
parent de8d26d791
commit 57ca3d7843
4 changed files with 89 additions and 27 deletions

View File

@@ -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<GuildPreview>}
*/

View File

@@ -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
* <info>This is only available on guilds with the `PUBLIC` feature</info>
* @type {?Snowflake}
*/
this.rulesChannelID = data.rules_channel_id;
/**
* The ID of the public updates channel for the guild
* <info>This is only available on guilds with the `PUBLIC` feature</info>
* 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
* <info>This is only available on guilds with the `PUBLIC` feature</info>
* @type {?TextChannel}
* @readonly
*/
@@ -593,7 +595,6 @@ class Guild extends Base {
/**
* Public updates channel for this guild
* <info>This is only available on guilds with the `PUBLIC` feature</info>
* @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<GuildPreview>}
*/
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<Guild>}
* @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<Guild>}
* @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<Guild>}
* @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

View File

@@ -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<Snowflake, GuildPreviewEmoji>}
*/
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<GuildPreview>}
*/
fetch() {

10
typings/index.d.ts vendored
View File

@@ -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<Guild>;
public setName(name: string, reason?: string): Promise<Guild>;
public setOwner(owner: GuildMemberResolvable, reason?: string): Promise<Guild>;
public setPreferredLocale(preferredLocale: string, reason?: string): Promise<Guild>;
public setPublicUpdatesChannel(publicUpdatesChannel: ChannelResolvable | null, reason?: string): Promise<Guild>;
public setRegion(region: string, reason?: string): Promise<Guild>;
public setRolePositions(rolePositions: RolePosition[]): Promise<Guild>;
public setRulesChannel(rulesChannel: ChannelResolvable | null, reason?: string): Promise<Guild>;
public setSplash(splash: Base64Resolvable | null, reason?: string): Promise<Guild>;
public setSystemChannel(systemChannel: ChannelResolvable | null, reason?: string): Promise<Guild>;
public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise<Guild>;
@@ -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'