mirror of
https://github.com/discordjs/discord.js.git
synced 2026-03-17 20:13:30 +01:00
Add VoiceChannel#full and improve joinable/join permission checks (#1100)
* Improve voice channel join permission checks * Update ClientVoiceManager.js
This commit is contained in:
committed by
Schuyler Cebulskie
parent
7cb5b22ebb
commit
d10ca8e7ba
@@ -79,7 +79,13 @@ class ClientVoiceManager {
|
|||||||
joinChannel(channel) {
|
joinChannel(channel) {
|
||||||
return new Promise((resolve, reject) => {
|
return new Promise((resolve, reject) => {
|
||||||
if (this.pending.get(channel.guild.id)) throw new Error('Already connecting to this guild\'s voice server.');
|
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);
|
const existingConnection = this.connections.get(channel.guild.id);
|
||||||
if (existingConnection) {
|
if (existingConnection) {
|
||||||
|
|||||||
@@ -45,13 +45,23 @@ class VoiceChannel extends GuildChannel {
|
|||||||
return null;
|
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
|
* Checks if the client has permission join the voice channel
|
||||||
* @type {boolean}
|
* @type {boolean}
|
||||||
*/
|
*/
|
||||||
get joinable() {
|
get joinable() {
|
||||||
if (this.client.browser) return false;
|
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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user