Skip to content

Commit

Permalink
Remove voice client when bot disconnects (#1273)
Browse files Browse the repository at this point in the history
* Remove voice client when bot disconnects

* Fix wrong logic caused by moving the code
  • Loading branch information
Dorukyum authored Apr 18, 2022
1 parent 7b2e527 commit 353bb56
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions discord/state.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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"])
Expand Down

0 comments on commit 353bb56

Please sign in to comment.