diff --git a/src/client/Client.js b/src/client/Client.js index 99b81055e813..dd00cb3f3f4c 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -404,11 +404,11 @@ class Client extends BaseClient { } /** - * Obtains the widget of a guild from Discord, available for guilds with the widget enabled. - * @param {GuildResolvable} guild The guild to fetch the widget for + * Obtains the widget data of a guild from Discord, available for guilds with the widget enabled. + * @param {GuildResolvable} guild The guild to fetch the widget data for * @returns {Promise} */ - async fetchWidget(guild) { + async fetchGuildWidget(guild) { const id = this.guilds.resolveId(guild); if (!id) throw new TypeError('INVALID_TYPE', 'guild', 'GuildResolvable'); const data = await this.api.guilds(id, 'widget.json').get(); diff --git a/src/structures/Guild.js b/src/structures/Guild.js index f217f8f51e7b..ec927b435a58 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -669,29 +669,42 @@ class Guild extends AnonymousGuild { } /** - * Data for the Guild Widget object - * @typedef {Object} GuildWidget + * Fetches the guild widget data, requires the widget to be enabled. + * @returns {Promise} + * @example + * // 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 channel + * @property {?GuildChannel} channel The widget invite channel */ /** - * The Guild Widget object - * @typedef {Object} GuildWidgetData + * The Guild Widget Settings object + * @typedef {Object} GuildWidgetSettingsData * @property {boolean} enabled Whether the widget is enabled - * @property {?GuildChannelResolvable} channel The widget channel + * @property {?GuildChannelResolvable} channel The widget invite channel */ /** - * Fetches the guild widget. - * @returns {Promise} + * Fetches the guild widget settings. + * @returns {Promise} * @example - * // Fetches the guild widget - * guild.fetchWidget() + * // 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} */ - 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, }) diff --git a/typings/index.d.ts b/typings/index.d.ts index 05cdfec7c5e3..882fa2755f7a 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -298,7 +298,7 @@ export class Client extends BaseClient { public fetchSticker(id: Snowflake): Promise; public fetchPremiumStickerPacks(): Promise>; public fetchWebhook(id: Snowflake, token?: string): Promise; - public fetchWidget(guild: GuildResolvable): Promise; + public fetchGuildWidget(guild: GuildResolvable): Promise; public generateInvite(options?: InviteGenerationOptions): string; public login(token?: string): Promise; public isReady(): this is Client; @@ -591,7 +591,8 @@ export class Guild extends AnonymousGuild { public fetchVanityData(): Promise; public fetchWebhooks(): Promise>; public fetchWelcomeScreen(): Promise; - public fetchWidget(): Promise; + public fetchWidget(): Promise; + public fetchWidgetSettings(): Promise; public leave(): Promise; public setAFKChannel(afkChannel: ChannelResolvable | null, reason?: string): Promise; public setAFKTimeout(afkTimeout: number, reason?: string): Promise; @@ -617,7 +618,7 @@ export class Guild extends AnonymousGuild { public setSystemChannel(systemChannel: ChannelResolvable | null, reason?: string): Promise; public setSystemChannelFlags(systemChannelFlags: SystemChannelFlagsResolvable, reason?: string): Promise; public setVerificationLevel(verificationLevel: VerificationLevel | number, reason?: string): Promise; - public setWidget(widget: GuildWidgetData, reason?: string): Promise; + public setWidgetSettings(settings: GuildWidgetSettingsData, reason?: string): Promise; public toJSON(): unknown; } @@ -3527,7 +3528,7 @@ export interface GuildCreateOptions { verificationLevel?: VerificationLevel | number; } -export interface GuildWidget { +export interface GuildWidgetSettings { enabled: boolean; channel: GuildChannel | null; } @@ -3618,7 +3619,7 @@ export interface GuildPruneMembersOptions { roles?: RoleResolvable[]; } -export interface GuildWidgetData { +export interface GuildWidgetSettingsData { enabled: boolean; channel: GuildChannelResolvable | null; }