From dd446475371cdbd476e0cb11f79b996d0756e10f Mon Sep 17 00:00:00 2001 From: Amish Shah Date: Mon, 29 Apr 2019 19:24:27 +0100 Subject: [PATCH] voice: Guild.voiceConnection => Guild.voice.connection --- src/client/voice/VoiceConnection.js | 2 +- src/structures/Guild.js | 9 +++++++++ src/structures/VoiceState.js | 11 +++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/client/voice/VoiceConnection.js b/src/client/voice/VoiceConnection.js index b532d0c5e..947e19122 100644 --- a/src/client/voice/VoiceConnection.js +++ b/src/client/voice/VoiceConnection.js @@ -171,7 +171,7 @@ class VoiceConnection extends EventEmitter { * @type {VoiceState} */ get voice() { - return this.channel.guild.voiceStates.get(this.client.user.id); + return this.channel.guild.voice; } /** diff --git a/src/structures/Guild.js b/src/structures/Guild.js index 1b5987f1f..4f5f02c5b 100644 --- a/src/structures/Guild.js +++ b/src/structures/Guild.js @@ -398,6 +398,15 @@ class Guild extends Base { null); } + /** + * The voice state for the client user of this guild, if any + * @type {?VoiceState} + * @readonly + */ + get voice() { + return this.me ? this.me.voice : null; + } + /** * Returns the GuildMember form of a User object, if the user is present in the guild. * @param {UserResolvable} user The user that you want to obtain the GuildMember of diff --git a/src/structures/VoiceState.js b/src/structures/VoiceState.js index d74fc6aa0..0b5f2b058 100644 --- a/src/structures/VoiceState.js +++ b/src/structures/VoiceState.js @@ -1,6 +1,7 @@ 'use strict'; const Base = require('./Base'); +const { browser } = require('../util/Constants'); /** * Represents the voice state for a Guild Member. @@ -77,6 +78,16 @@ class VoiceState extends Base { return this.guild.channels.get(this.channelID) || null; } + /** + * If this is a voice state of the client user, then this will refer to the active VoiceConnection for this guild + * @type {?VoiceConnection} + * @readonly + */ + get connection() { + if (browser || this.id !== this.guild.me.id) return null; + return this.client.voice.connections.get(this.guild.id) || null; + } + /** * Whether this member is either self-deafened or server-deafened * @type {?boolean}