feat(core): automatically leave voice channel when empty

This commit is contained in:
Ryan 2025-01-03 00:01:08 -05:00
parent 409373ee27
commit 92a0eee92c
Signed by: ErrorNoInternet
GPG Key ID: 2486BFB7B1E6A4A3
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__)

View File

@ -28,3 +28,12 @@ async def on_message(message):
await events.trigger_dynamic_handlers("on_message", message)
await core.on_message(message)
@client.event
async def on_voice_state_update(member, before, after):
await events.trigger_dynamic_handlers(
"on_voice_state_update", member, before, after
)
await core.on_voice_state_update(member, before, after)

View File

@ -7,6 +7,7 @@ command_locks = {}
intents = disnake.Intents.default()
intents.message_content = True
intents.members = True
client = disnake.Client(intents=intents)
start_time = time.time()