fix: delete player objects when disconnected

This commit is contained in:
2026-04-11 17:45:05 -04:00
parent ed3afdbeae
commit 8194268ce1

View File

@@ -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):