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

@@ -232,6 +232,16 @@ class Guild {
return this.members.get(this.ownerID);
}
/**
* If the client is connected to any voice channel in this guild, this will be the relevant
* VoiceConnection.
* @type {VoiceConnection}
* @readonly
*/
get voiceConnection() {
return this.client.voice.connections.get(this.id) || null;
}
/**
* The `#general` GuildChannel of the server.
* @type {GuildChannel}
@@ -690,16 +700,6 @@ class Guild {
}
}
}
/**
* If the client is connected to any voice channel in this guild, this will be the relevant
* VoiceConnection.
* @type {VoiceConnection}
* @readonly
*/
get voiceConnection() {
return this.client.voice.connections.get(this.id);
}
}
module.exports = Guild;

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;