feat(core): automatically leave voice channel when empty

This commit is contained in:
2025-01-03 00:01:08 -05:00
parent 409373ee27
commit 92a0eee92c
3 changed files with 24 additions and 1 deletions

15
core.py
View File

@@ -12,7 +12,7 @@ import commands
import constants
import core
import utils
from state import command_locks
from state import client, command_locks
async def on_message(message):
@@ -123,6 +123,19 @@ async def on_message(message):
)
async def on_voice_state_update(_, before, after):
is_empty = lambda channel: [m.id for m in (channel.members if channel else [])] == [
client.user.id
]
c = None
if is_empty(before.channel):
c = before.channel
elif is_empty(after.channel):
c = after.channel
if c:
await c.guild.voice_client.disconnect()
def rreload(reloaded_modules, module):
reloaded_modules.add(module.__name__)