From d10ca8e7baf62da1d8472901c83d02992d101d2e Mon Sep 17 00:00:00 2001 From: Programmix Date: Sat, 14 Jan 2017 20:32:17 -0800 Subject: [PATCH] Add VoiceChannel#full and improve joinable/join permission checks (#1100) * Improve voice channel join permission checks * Update ClientVoiceManager.js --- src/client/voice/ClientVoiceManager.js | 8 +++++++- src/structures/VoiceChannel.js | 12 +++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/src/client/voice/ClientVoiceManager.js b/src/client/voice/ClientVoiceManager.js index ea8374540..80725de01 100644 --- a/src/client/voice/ClientVoiceManager.js +++ b/src/client/voice/ClientVoiceManager.js @@ -79,7 +79,13 @@ class ClientVoiceManager { joinChannel(channel) { return new Promise((resolve, reject) => { if (this.pending.get(channel.guild.id)) throw new Error('Already connecting to this guild\'s voice server.'); - if (!channel.joinable) throw new Error('You do not have permission to join this voice channel.'); + if (!channel.joinable) { + if (channel.full) { + throw new Error('You do not have permission to join this voice channel; it is full.'); + } else { + throw new Error('You do not have permission to join this voice channel.'); + } + } const existingConnection = this.connections.get(channel.guild.id); if (existingConnection) { diff --git a/src/structures/VoiceChannel.js b/src/structures/VoiceChannel.js index ad18a94b0..e6d5b637f 100644 --- a/src/structures/VoiceChannel.js +++ b/src/structures/VoiceChannel.js @@ -45,13 +45,23 @@ class VoiceChannel extends GuildChannel { return null; } + /** + * Checks if the voice channel is full + * @type {boolean} + */ + get full() { + return this.members.size >= this.userLimit; + } + /** * Checks if the client has permission join the voice channel * @type {boolean} */ get joinable() { if (this.client.browser) return false; - return this.permissionsFor(this.client.user).hasPermission('CONNECT'); + if (!this.permissionsFor(this.client.user).hasPermission('CONNECT')) return false; + if (this.full && !this.permissionsFor(this.client.user).hasPermission('MOVE_MEMBERS')) return false; + return true; } /**