From 84153be8940328cd72c9406eff6f72c942fba938 Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Fri, 25 Aug 2017 23:41:26 +0100 Subject: [PATCH] Fix #1281 --- src/structures/GuildMember.js | 22 ++++++++++++++++++---- src/structures/VoiceChannel.js | 1 + 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index 43f5b3092..420208cb3 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -354,9 +354,14 @@ class GuildMember extends Base { } else { endpoint = endpoint.members(this.id); } - return endpoint.patch({ data, reason }).then(newData => { + return endpoint.patch({ data, reason }).then(() => { const clone = this._clone(); - clone._patch(newData); + data.user = this.user; + clone._patch(data); + clone._frozenVoiceState = this.voiceState; + if (typeof data.mute !== 'undefined') clone._frozenVoiceState.mute = data.mute; + if (typeof data.deaf !== 'undefined') clone._frozenVoiceState.mute = data.deaf; + if (typeof data.channel_id !== 'undefined') clone._frozenVoiceState.channel_id = data.channel_id; return clone; }); } @@ -412,7 +417,11 @@ class GuildMember extends Base { if (this._roles.includes(role.id)) return Promise.resolve(this); return this.client.api.guilds(this.guild.id).members(this.user.id).roles(role.id) .put({ reason }) - .then(() => this); + .then(() => { + const clone = this._clone(); + if (!clone._roles.includes(role.id)) clone._roles.push(role.id); + return clone; + }); } /** @@ -446,7 +455,12 @@ class GuildMember extends Base { if (!this._roles.includes(role.id)) return Promise.resolve(this); return this.client.api.guilds(this.guild.id).members(this.user.id).roles(role.id) .delete({ reason }) - .then(() => this); + .then(() => { + const clone = this._clone(); + const index = clone._roles.indexOf(role.id); + if (~index) clone._roles.splice(index, 1); + return clone; + }); } /** diff --git a/src/structures/VoiceChannel.js b/src/structures/VoiceChannel.js index 2bfaffe79..9c6356f68 100644 --- a/src/structures/VoiceChannel.js +++ b/src/structures/VoiceChannel.js @@ -18,6 +18,7 @@ class VoiceChannel extends GuildChannel { } _patch(data) { + super._patch(data); /** * The bitrate of this voice channel * @type {number}