From fe51f13f13b26bbd84874ff6e4e265ce2444574a Mon Sep 17 00:00:00 2001 From: Rafael Vargas Date: Mon, 3 Jan 2022 21:39:58 -0400 Subject: [PATCH] Fixing loop error and adding automatic cleaning of bot messages --- vulkanbot/music/Music.py | 34 ++++++++++++++++++++++------------ 1 file changed, 22 insertions(+), 12 deletions(-) diff --git a/vulkanbot/music/Music.py b/vulkanbot/music/Music.py index 6f75420..1850a91 100644 --- a/vulkanbot/music/Music.py +++ b/vulkanbot/music/Music.py @@ -25,18 +25,12 @@ class Music(commands.Cog): 'options': '-vn'} def __play_next(self, error, ctx): - while True: - if len(self.__playlist) > 0: - source = self.__playlist.next_song() - if source == None: # If there is not a source for the song - continue - - coro = self.__play_music(ctx, source) - self.__bot.loop.create_task(coro) - break - else: - self.__playing = False - break + source = self.__playlist.next_song() + if source != None: # If there is not a source for the song + coro = self.__play_music(ctx, source) + self.__bot.loop.create_task(coro) + else: + self.__playing = False async def __play_music(self, ctx, song): self.__playing = True @@ -200,6 +194,7 @@ class Music(commands.Cog): title = 'Song Playing Now' current_song = self.__playlist.current + await self.__clean_messages(ctx) await ctx.send(embed=current_song.embed(title=title)) @commands.command(name='shuffle', help=config.HELP_SHUFFLE) @@ -244,6 +239,21 @@ class Music(commands.Cog): ) await ctx.send(embed=embedvc) + async def __clean_messages(self, ctx): + """Clear Bot messages if send recently""" + last_messages = await ctx.channel.history(limit=5).flatten() + + for message in last_messages: + try: + if message.author == self.__bot.user: + if len(message.embeds) > 0: + embed = message.embeds[0] + if embed.title == 'Song Playing Now': + await message.delete() + except Exception as e: + print(e) + continue + def setup(bot): bot.add_cog(Music(bot))