From 7ba94400535b9ece59094f34ad01d826cfcbc1b2 Mon Sep 17 00:00:00 2001 From: Sugden <28943913+NotSugden@users.noreply.github.com> Date: Mon, 31 Aug 2020 08:16:53 +0100 Subject: [PATCH] fix(Guild): cache fetched widget data (#4760) --- src/structures/Guild.js | 35 ++++++++++------------------------- 1 file changed, 10 insertions(+), 25 deletions(-) diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 91245fd9c..e66e6a612 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -883,13 +883,7 @@ class Guild extends Base { * .catch(console.error); */ fetchEmbed() { - return this.client.api - .guilds(this.id) - .embed.get() - .then(data => ({ - enabled: data.enabled, - channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null, - })); + return this.fetchWidget(); } /** @@ -901,14 +895,14 @@ class Guild extends Base { * .then(widget => console.log(`The widget is ${widget.enabled ? 'enabled' : 'disabled'}`)) * .catch(console.error); */ - fetchWidget() { - return this.client.api - .guilds(this.id) - .widget.get() - .then(data => ({ - enabled: data.enabled, - channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null, - })); + async fetchWidget() { + const data = await this.client.api.guilds(this.id).widget.get(); + this.widgetEnabled = this.embedEnabled = data.enabled; + this.widgetChannelID = this.embedChannelID = data.channel_id; + return { + enabled: data.enabled, + channel: data.channel_id ? this.channels.cache.get(data.channel_id) : null, + }; } /** @@ -1387,16 +1381,7 @@ class Guild extends Base { * @deprecated */ 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); + return this.setWidget(embed, reason); } /**