From 986e6da196525ddf64d666a71c5dc70a450e6cd1 Mon Sep 17 00:00:00 2001 From: Kyra Date: Sat, 20 Jan 2018 19:30:30 +0100 Subject: [PATCH 1/2] Fix(GuildChannel#clone) options.parent not accepting (falsy) null. (#2262) * Fixed (falsy) options not being set correctly * Requested changes. As a side note, I also default `options.withPermissions` for simplicity, and because it gets ignored in [`GuildChannelStore#create()`](https://discord.js.org/#/docs/main/master/class/GuildChannelStore?scrollTo=create). * Fixed the overwrites option --- src/structures/GuildChannel.js | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) diff --git a/src/structures/GuildChannel.js b/src/structures/GuildChannel.js index c4d4c7bbf..a79f11bae 100644 --- a/src/structures/GuildChannel.js +++ b/src/structures/GuildChannel.js @@ -445,18 +445,21 @@ class GuildChannel extends Channel { * @param {string} [options.reason] Reason for cloning this channel * @returns {Promise} */ - clone({ name = this.name, withPermissions = true, withTopic = true, nsfw, parent, bitrate, userLimit, reason } = {}) { - const options = { - overwrites: withPermissions ? this.permissionOverwrites : [], - nsfw: typeof nsfw === 'undefined' ? this.nsfw : nsfw, - parent: parent || this.parent, - bitrate: bitrate || this.bitrate, - userLimit: userLimit || this.userLimit, - reason, - type: this.type, - }; - return this.guild.channels.create(name, options) - .then(channel => withTopic ? channel.setTopic(this.topic) : channel); + clone(options = {}) { + if (typeof options.withPermissions === 'undefined') options.withPermissions = true; + Util.mergeDefault({ + name: this.name, + overwrites: options.withPermissions ? this.permissionOverwrites : [], + withTopic: true, + nsfw: this.nsfw, + parent: this.parent, + bitrate: this.bitrate, + userLimit: this.userLimit, + reason: null, + }, options); + options.type = this.type; + return this.guild.channels.create(options.name, options) + .then(channel => options.withTopic ? channel.setTopic(this.topic) : channel); } /** From 93e083da4fd8a936d534abb6d16e42f37837da4d Mon Sep 17 00:00:00 2001 From: Pascal Date: Sun, 21 Jan 2018 07:30:59 +0100 Subject: [PATCH 2/2] fix(Guild): memberCount not decrementing when an uncached member leaves This leads to GuildMemberStore#_fetchMany to always reject because it expects more member than possible. Also no longer call the GuildMemberRemove handler locally to not decrement twice. --- src/client/actions/GuildMemberRemove.js | 2 +- src/structures/GuildMember.js | 7 +------ 2 files changed, 2 insertions(+), 7 deletions(-) diff --git a/src/client/actions/GuildMemberRemove.js b/src/client/actions/GuildMemberRemove.js index b649eba8d..95bff6abf 100644 --- a/src/client/actions/GuildMemberRemove.js +++ b/src/client/actions/GuildMemberRemove.js @@ -8,8 +8,8 @@ class GuildMemberRemoveAction extends Action { let member = null; if (guild) { member = guild.members.get(data.user.id); + guild.memberCount--; if (member) { - guild.memberCount--; guild.members.remove(member.id); if (client.status === Status.READY) client.emit(Events.GUILD_MEMBER_REMOVE, member); } diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index 038527929..bee96c814 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -526,12 +526,7 @@ class GuildMember extends Base { */ kick(reason) { return this.client.api.guilds(this.guild.id).members(this.user.id).delete({ reason }) - .then(() => - this.client.actions.GuildMemberRemove.handle({ - guild_id: this.guild.id, - user: this.user, - }).member - ); + .then(() => this); } /**