From 9bb883161900223473bb7a669b7f54cae2532a21 Mon Sep 17 00:00:00 2001 From: SpaceEEC Date: Wed, 9 May 2018 16:38:28 +0200 Subject: [PATCH] feat(GuildMember): add manageable getter --- src/structures/GuildMember.js | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) diff --git a/src/structures/GuildMember.js b/src/structures/GuildMember.js index f77c8a455..ac4daa7ac 100644 --- a/src/structures/GuildMember.js +++ b/src/structures/GuildMember.js @@ -254,17 +254,24 @@ class GuildMember { return new Permissions(this, permissions); } + /** + * Whether the member is manageable in terms of role hierarchy by the client user + * @type {boolean} + * @readonly + */ + get manageable() { + if (this.user.id === this.guild.ownerID) return false; + if (this.user.id === this.client.user.id) return false; + return this.guild.me.highestRole.comparePositionTo(this.highestRole) > 0; + } + /** * Whether the member is kickable by the client user * @type {boolean} * @readonly */ get kickable() { - if (this.user.id === this.guild.ownerID) return false; - if (this.user.id === this.client.user.id) return false; - const clientMember = this.guild.member(this.client.user); - if (!clientMember.permissions.has(Permissions.FLAGS.KICK_MEMBERS)) return false; - return clientMember.highestRole.comparePositionTo(this.highestRole) > 0; + return this.manageable && this.guild.me.permissions.has(Permissions.FLAGS.KICK_MEMBERS); } /** @@ -273,11 +280,7 @@ class GuildMember { * @readonly */ get bannable() { - if (this.user.id === this.guild.ownerID) return false; - if (this.user.id === this.client.user.id) return false; - const clientMember = this.guild.member(this.client.user); - if (!clientMember.permissions.has(Permissions.FLAGS.BAN_MEMBERS)) return false; - return clientMember.highestRole.comparePositionTo(this.highestRole) > 0; + return this.manageable && this.guild.me.permissions.has(Permissions.FLAGS.BAN_MEMBERS); } /**