fix: ensure VIEW_CHANNEL permissions before trying to join (#3046)

* fix: ensure VIEW_CHANNEL permissions before joining

* nit(GuildChannel): remove the redundant truthy check
This commit is contained in:
SpaceEEC
2019-02-10 16:21:59 +01:00
committed by Amish Shah
parent ff95e587cb
commit 7324a993ed
3 changed files with 17 additions and 4 deletions

View File

@@ -523,10 +523,21 @@ class GuildChannel extends Channel {
* @readonly
*/
get manageable() {
if (this.client.user.id === this.guild.ownerID) return true;
if (!this.viewable) return false;
return this.permissionsFor(this.client.user).has(Permissions.FLAGS.MANAGE_CHANNELS, false);
}
/**
* Whether the channel is viewable by the client user
* @type {boolean}
* @readonly
*/
get viewable() {
if (this.client.user.id === this.guild.ownerID) return true;
const permissions = this.permissionsFor(this.client.user);
if (!permissions) return false;
return permissions.has([Permissions.FLAGS.MANAGE_CHANNELS, Permissions.FLAGS.VIEW_CHANNEL], false);
return permissions.has(Permissions.FLAGS.VIEW_CHANNEL, false);
}
/**

View File

@@ -71,14 +71,15 @@ class VoiceChannel extends GuildChannel {
}
/**
* Checks if the client has permission join the voice channel
* Whether the channel is joinable by the client user
* @type {boolean}
* @readonly
*/
get joinable() {
if (browser) return false;
if (!this.permissionsFor(this.client.user).has('CONNECT', false)) return false;
if (this.full && !this.permissionsFor(this.client.user).has('MOVE_MEMBERS', false)) return false;
if (!this.viewable) return false;
if (!this.permissionsFor(this.client.user).has(Permissions.FLAGS.CONNECT, false)) return false;
if (this.full && !this.permissionsFor(this.client.user).has(Permissions.FLAGS.MOVE_MEMBERS, false)) return false;
return true;
}

1
typings/index.d.ts vendored
View File

@@ -523,6 +523,7 @@ declare module 'discord.js' {
public readonly permissionsLocked: boolean;
public readonly position: number;
public rawPosition: number;
public readonly viewable: boolean;
public clone(options?: GuildChannelCloneOptions): Promise<GuildChannel>;
public createInvite(options?: InviteOptions): Promise<Invite>;
public createOverwrite(userOrRole: RoleResolvable | UserResolvable, options: PermissionOverwriteOption, reason?: string): Promise<GuildChannel>;