From 0114ea5cce0bffd2666daaf18fe5c70cea8a2437 Mon Sep 17 00:00:00 2001 From: deflax Date: Sun, 27 Mar 2022 23:23:10 -0400 Subject: [PATCH] disconnects if no more users are left --- main.py | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/main.py b/main.py index 5f20098..bb93ab9 100644 --- a/main.py +++ b/main.py @@ -66,25 +66,30 @@ async def on_voice_state_update(member, before, after): :return: """ global isConnected + + if member.bot: + #print("[INFO] self event detection") + return voice_channel = await bot.fetch_channel(voice_channel_id) member_ids = len(voice_channel.voice_states.keys()) debug_channel = await bot.fetch_channel(text_channel_id) - if member_ids > 0: - await debug_channel.send('] voice activity. voice #' + voice_channel_id + ' member count: ' + str(member_ids)) + await debug_channel.send('] voice #' + voice_channel_id + ' member count: ' + str(member_ids)) - if member_ids > 1 and not isConnected: + if member_ids == 1 and isConnected == False: + isConnected = True await debug_channel.send('] connecting to #' + voice_channel_id) voiceChannel = await voice_channel.connect() - isConnected = True + return - if member_ids == 1 and isConnected: - await debug_channel.send('] disconnecting from #' + voice_channel_id) - voiceChannel = await voice_channel.connect() - await voiceChannel.disconnect() + if member_ids == 1 and isConnected == True: isConnected = False + await debug_channel.send('] disconnecting from #' + voice_channel_id) + for x in bot.voice_clients: + await x.disconnect() + return # Start the bot with multiprocess compatiblity if __name__ == "__main__":