feat(core): automatically leave voice channel when empty
This commit is contained in:
parent
409373ee27
commit
92a0eee92c
15
core.py
15
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__)
|
||||
|
||||
|
@ -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)
|
||||
|
Loading…
x
Reference in New Issue
Block a user