diff --git a/core.py b/core.py index 8335676..1bf0a09 100644 --- a/core.py +++ b/core.py @@ -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__) diff --git a/events.py b/events.py index 3d20e25..c656ee7 100644 --- a/events.py +++ b/events.py @@ -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) diff --git a/state.py b/state.py index 562673a..cce97bf 100644 --- a/state.py +++ b/state.py @@ -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()