diff --git a/src/structures/Guild.js b/src/structures/Guild.js index d80620364..a698c1049 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -483,6 +483,29 @@ class Guild extends Base { }); } + /** + * The Guild Embed object + * @typedef {Object} GuildEmbedData + * @property {boolean} enabled Whether the embed is enabled + * @property {?GuildChannel} channel The embed channel + */ + + /** + * Fetches the guild embed. + * @returns {Promise} + * @example + * // Fetches the guild embed + * guild.fetchEmbed() + * .then(embed => console.log(`The embed is ${embed.enabled ? 'enabled' : 'disabled'}`)) + * .catch(console.error); + */ + fetchEmbed() { + return this.client.api.guilds(this.id).embed.get().then(data => ({ + enabled: data.enabled, + channel: data.channel_id ? this.channels.get(data.channel_id) : null, + })); + } + /** * Fetches audit logs for this guild. * @param {Object} [options={}] Options for fetching audit logs @@ -790,6 +813,22 @@ class Guild extends Base { ); } + /** + * Edits the guild's embed. + * @param {GuildEmbedData} embed The embed for the guild + * @param {string} [reason] Reason for changing the guild's embed + * @returns {Promise} + */ + setEmbed(embed, reason) { + return this.client.api.guilds(this.id).embed.patch({ + data: { + enabled: embed.enabled, + channel_id: this.channels.resolveID(embed.channel), + }, + reason, + }).then(() => this); + } + /** * Leaves the guild. * @returns {Promise} diff --git a/typings/index.d.ts b/typings/index.d.ts index 6bd46c7fb..e4887937e 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -395,6 +395,7 @@ declare module 'discord.js' { public fetchVanityCode(): Promise; public fetchVoiceRegions(): Promise>; public fetchWebhooks(): Promise>; + public fetchEmbed(): Promise; public iconURL(options?: AvatarOptions): string; public leave(): Promise; public member(user: UserResolvable): GuildMember; @@ -410,6 +411,7 @@ declare module 'discord.js' { public setSplash(splash: Base64Resolvable, reason?: string): Promise; public setSystemChannel(systemChannel: ChannelResolvable, reason?: string): Promise; public setVerificationLevel(verificationLevel: number, reason?: string): Promise; + public setEmbed(embed: GuildEmbedData, reason?: string): Promise; public splashURL(options?: AvatarOptions): string; public toJSON(): object; public toString(): string; @@ -1698,6 +1700,11 @@ declare module 'discord.js' { splash?: Base64Resolvable; }; + type GuildEmbedData = { + enabled: boolean; + channel?: GuildChannelResolvable; + }; + type GuildFeatures = 'INVITE_SPLASH' | 'MORE_EMOJI' | 'VERIFIED'