Clean up voice channel join permissions check

This commit is contained in:
Schuyler Cebulskie
2016-10-25 20:41:23 -04:00
parent b2a4545c16
commit 05f73c3edf

View File

@@ -47,18 +47,15 @@ class ClientVoiceManager {
*/ */
sendVoiceStateUpdate(channel, options = {}) { sendVoiceStateUpdate(channel, options = {}) {
if (!this.client.user) throw new Error('Unable to join because there is no client user.'); if (!this.client.user) throw new Error('Unable to join because there is no client user.');
if (!channel.permissionsFor) {
if (channel.permissionsFor) { throw new Error('Channel does not support permissionsFor; is it really a voice channel?');
const permissions = channel.permissionsFor(this.client.user);
if (permissions) {
if (!permissions.hasPermission('CONNECT')) {
throw new Error('You do not have permission to connect to this voice channel.');
} }
} else { const permissions = channel.permissionsFor(this.client.user);
if (!permissions) {
throw new Error('There is no permission set for the client user in this channel - are they part of the guild?'); throw new Error('There is no permission set for the client user in this channel - are they part of the guild?');
} }
} else { if (!permissions.hasPermission('CONNECT')) {
throw new Error('Channel does not support permissionsFor; is it really a voice channel?'); throw new Error('You do not have permission to connect to this voice channel.');
} }
options = mergeDefault({ options = mergeDefault({