fix: delete player objects when disconnected
This commit is contained in:
@@ -15,7 +15,7 @@ import disnake_paginator
|
|||||||
from . import commands, utils
|
from . import commands, utils
|
||||||
from .commands import Command as C
|
from .commands import Command as C
|
||||||
from .constants import EMBED_COLOR, OWNERS, PREFIX, RELOADABLE_MODULES
|
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):
|
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):
|
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):
|
def is_empty(channel):
|
||||||
return [m.id for m in (channel.members if channel else [])] == [client.user.id]
|
return [m.id for m in (channel.members if channel else [])] == [client.user.id]
|
||||||
|
|
||||||
channel = None
|
if is_empty(after.channel):
|
||||||
if is_empty(before.channel):
|
if after.channel.guild.id in players:
|
||||||
channel = before.channel
|
del players[after.channel.guild.id]
|
||||||
elif is_empty(after.channel):
|
await after.channel.guild.voice_client.disconnect()
|
||||||
channel = after.channel
|
|
||||||
|
|
||||||
if channel:
|
|
||||||
await channel.guild.voice_client.disconnect()
|
|
||||||
|
|
||||||
|
|
||||||
def rreload(reloaded_modules, module):
|
def rreload(reloaded_modules, module):
|
||||||
|
|||||||
Reference in New Issue
Block a user