Fix & clean up Guild.voiceConnection and VoiceChannel.connection

This commit is contained in:
Schuyler Cebulskie
2016-09-21 16:01:08 -04:00
parent 15d7f8e2fe
commit a27f6c96bb
2 changed files with 22 additions and 24 deletions

View File

@@ -34,6 +34,18 @@ class VoiceChannel extends GuildChannel {
this.userLimit = data.user_limit;
}
/**
* If connected to this guild's voice channel and the client is marked as being in this voice channel,
* then this will give the relevant voice connection.
* @type {VoiceConnection}
* @readonly
*/
get connection() {
const connection = this.guild.voiceConnection;
if (connection && connection.channel.id === this.id) return connection;
return null;
}
/**
* Sets the bitrate of the channel
* @param {number} bitrate The new bitrate
@@ -71,20 +83,6 @@ class VoiceChannel extends GuildChannel {
const connection = this.client.voice.connections.get(this.guild.id);
if (connection && connection.channel.id === this.id) connection.disconnect();
}
/**
* If connected to this guild's voice channel and the client is marked as being in this voice channel,
* then this will give the relevant voice connection.
* @type {VoiceConnection}
* @readonly
*/
get connection() {
const connection = this.client.voice.connections.get(this.guild.id);
if (connection.channel.id === this.id) {
return connection;
}
return undefined;
}
}
module.exports = VoiceChannel;