diff --git a/discord/state.py b/discord/state.py index 0ec03cebcd..c2c55d9ac5 100644 --- a/discord/state.py +++ b/discord/state.py @@ -1544,12 +1544,6 @@ def parse_voice_state_update(self, data) -> None: # self.user is *always* cached when this is called self_id = self.user.id # type: ignore if guild is not None: - if int(data["user_id"]) == self_id: - voice = self._get_voice_client(guild.id) - if voice is not None: - coro = voice.on_voice_state_update(data) - asyncio.create_task(logging_coroutine(coro, info="Voice Protocol voice state update handler")) - member, before, after = guild._update_voice_state(data, channel_id) # type: ignore if member is not None: if flags.voice: @@ -1567,6 +1561,15 @@ def parse_voice_state_update(self, data) -> None: data["user_id"], ) + if int(data["user_id"]) == self_id: + voice = self._get_voice_client(guild.id) + if voice is not None: + if guild.me.voice is None: + self._remove_voice_client(guild.id) + coro = voice.on_voice_state_update(data) + asyncio.create_task(logging_coroutine(coro, info="Voice Protocol voice state update handler")) + + def parse_voice_server_update(self, data) -> None: try: key_id = int(data["guild_id"])