diff --git a/cogs/music/util.py b/cogs/music/util.py index 000d2a2..23a4a75 100644 --- a/cogs/music/util.py +++ b/cogs/music/util.py @@ -90,12 +90,15 @@ async def display_server_queue(ctx: Context, songs, n): # Converts seconds into more readable format def format_time(seconds): - minutes, seconds = divmod(seconds, 60) - hours, minutes = divmod(minutes, 60) + try: + minutes, seconds = divmod(seconds, 60) + hours, minutes = divmod(minutes, 60) - if hours > 0: - return f"{hours}:{minutes:02d}:{seconds:02d}" - elif minutes > 0: - return f"{minutes}:{seconds:02d}" - else: - return f"{seconds} seconds" + if hours > 0: + return f"{hours}:{minutes:02d}:{seconds:02d}" + elif minutes > 0: + return f"{minutes}:{seconds:02d}" + else: + return f"{seconds} seconds" + except: + return "" diff --git a/main.py b/main.py index 68a512c..e82b22e 100644 --- a/main.py +++ b/main.py @@ -1,4 +1,5 @@ import discord +from discord.ext import tasks from bot import Astro import config import help @@ -6,4 +7,16 @@ import help client = Astro(command_prefix=config.get_prefix(), intents=discord.Intents.all()) client.help_command = help.AstroHelp() -client.run(config.get_login("dev")) \ No newline at end of file +@client.event +async def on_voice_state_update(member, before, after): + if member == client.user: + return #ignore self actions + + # get the vc + voice_client = discord.utils.get(client.voice_clients, guild=member.guild) + + # if the bot is the only connected member, leave + if voice_client and len(voice_client.channel.members) == 1: + await voice_client.disconnect() + +client.run(config.get_login("live"))