diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 48b45a59c..429e3ca59 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -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; diff --git a/src/structures/VoiceChannel.js b/src/structures/VoiceChannel.js index 1f37f0caa..eb199da9e 100644 --- a/src/structures/VoiceChannel.js +++ b/src/structures/VoiceChannel.js @@ -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;