mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-10 08:33:30 +01:00
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:
@@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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
1
typings/index.d.ts
vendored
@@ -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>;
|
||||
|
||||
Reference in New Issue
Block a user