diff --git a/errornocord/core.py b/errornocord/core.py index 0540e90..c89a6c7 100644 --- a/errornocord/core.py +++ b/errornocord/core.py @@ -15,7 +15,7 @@ import disnake_paginator from . import commands, utils from .commands import Command as C from .constants import EMBED_COLOR, OWNERS, PREFIX, RELOADABLE_MODULES -from .state import client, command_cooldowns, command_locks, idle_tracker +from .state import client, command_cooldowns, command_locks, idle_tracker, players async def on_message(message, edited=False): @@ -149,17 +149,21 @@ async def on_message(message, edited=False): async def on_voice_state_update(_, before, after): + if not before.channel and after.channel: + return + + if before.channel and not after.channel: + if before.channel.guild.id in players: + del players[before.channel.guild.id] + return + def is_empty(channel): return [m.id for m in (channel.members if channel else [])] == [client.user.id] - channel = None - if is_empty(before.channel): - channel = before.channel - elif is_empty(after.channel): - channel = after.channel - - if channel: - await channel.guild.voice_client.disconnect() + if is_empty(after.channel): + if after.channel.guild.id in players: + del players[after.channel.guild.id] + await after.channel.guild.voice_client.disconnect() def rreload(reloaded_modules, module):