feat(Guild): add fetchWidget() for getting widget data (#6180)

This commit is contained in:
Advaith
2021-07-27 03:15:31 -07:00
committed by GitHub
parent 2f1cc1fc27
commit b22272f860
3 changed files with 46 additions and 32 deletions

View File

@@ -669,29 +669,42 @@ class Guild extends AnonymousGuild {
}
/**
* Data for the Guild Widget object
* @typedef {Object} GuildWidget
* @property {boolean} enabled Whether the widget is enabled
* @property {?GuildChannel} channel The widget channel
*/
/**
* The Guild Widget object
* @typedef {Object} GuildWidgetData
* @property {boolean} enabled Whether the widget is enabled
* @property {?GuildChannelResolvable} channel The widget channel
*/
/**
* Fetches the guild widget.
* @returns {Promise<GuildWidget>}
* Fetches the guild widget data, requires the widget to be enabled.
* @returns {Promise<Widget>}
* @example
* // Fetches the guild widget
* // Fetches the guild widget data
* guild.fetchWidget()
* .then(widget => console.log(`The widget shows ${widget.channels.size} channels`))
* .catch(console.error);
*/
fetchWidget() {
return this.client.fetchGuildWidget(this.id);
}
/**
* Data for the Guild Widget Settings object
* @typedef {Object} GuildWidgetSettings
* @property {boolean} enabled Whether the widget is enabled
* @property {?GuildChannel} channel The widget invite channel
*/
/**
* The Guild Widget Settings object
* @typedef {Object} GuildWidgetSettingsData
* @property {boolean} enabled Whether the widget is enabled
* @property {?GuildChannelResolvable} channel The widget invite channel
*/
/**
* Fetches the guild widget settings.
* @returns {Promise<GuildWidgetSettings>}
* @example
* // Fetches the guild widget settings
* guild.fetchWidgetSettings()
* .then(widget => console.log(`The widget is ${widget.enabled ? 'enabled' : 'disabled'}`))
* .catch(console.error);
*/
async fetchWidget() {
async fetchWidgetSettings() {
const data = await this.client.api.guilds(this.id).widget.get();
this.widgetEnabled = data.enabled;
this.widgetChannelId = data.channel_id;
@@ -1234,18 +1247,18 @@ class Guild extends AnonymousGuild {
}
/**
* Edits the guild's widget.
* @param {GuildWidgetData} widget The widget for the guild
* @param {string} [reason] Reason for changing the guild's widget
* Edits the guild's widget settings.
* @param {GuildWidgetSettingsData} settings The widget settings for the guild
* @param {string} [reason] Reason for changing the guild's widget settings
* @returns {Promise<Guild>}
*/
setWidget(widget, reason) {
setWidgetSettings(settings, reason) {
return this.client.api
.guilds(this.id)
.widget.patch({
data: {
enabled: widget.enabled,
channel_id: this.channels.resolveId(widget.channel),
enabled: settings.enabled,
channel_id: this.channels.resolveId(settings.channel),
},
reason,
})