Skip to content

Commit

Permalink
Remove voice client when bot disconnects
Browse files Browse the repository at this point in the history
  • Loading branch information
Dorukyum committed Apr 17, 2022
1 parent ea69bf5 commit e6a5599
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 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 @@ -1560,6 +1554,14 @@ def parse_voice_state_update(self, data) -> None:
elif channel_id is not None:
guild._add_member(member)

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"))

self.dispatch("voice_state_update", member, before, after)
else:
_log.debug(
Expand Down

0 comments on commit e6a5599

Please sign in to comment.