feat: GuildEmbed support (#2766)

* feat: Guild embed support

* docs: Fixed setEmbed's reason argument not being optional

* fix: Guild#setEmbed should return the guild itself for consistency

* docs: Updated typings

* fix: Requested change
This commit is contained in:
Kyra
2018-08-21 10:40:47 +02:00
committed by SpaceEEC
parent 0401b8ad77
commit 5787deef26
2 changed files with 46 additions and 0 deletions

View File

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