From 4dea852995c2ca1b16d09e0f04be13d5328af5ea Mon Sep 17 00:00:00 2001 From: ekzyis Date: Thu, 4 Nov 2021 01:29:13 +0100 Subject: [PATCH 1/3] Add command error logging --- src/error.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/error.py b/src/error.py index 8f6526a..7bca386 100644 --- a/src/error.py +++ b/src/error.py @@ -14,7 +14,9 @@ class ErrorHandler(commands.Cog): @commands.Cog.listener() async def on_command_error(self, ctx: commands.Context, error: commands.CommandError): + command_name = ctx.command.name if isinstance(error, commands.CommandNotFound): + self.logger.error(error) return if isinstance(error, commands.MissingPermissions): message = "You are missing the required permissions to run this command!" @@ -25,6 +27,7 @@ class ErrorHandler(commands.Cog): else: message = "Oh no! Something went wrong while running the command!" + self.logger.error('Error during command "%s": %s', command_name, message) embed = ErrorMessage(message) await ctx.send(embed=embed) From c11c87ccae567c5c1d5c7f9fe185f52ae7390caa Mon Sep 17 00:00:00 2001 From: ekzyis Date: Thu, 4 Nov 2021 01:43:52 +0100 Subject: [PATCH 2/3] Add more INFO logging --- src/bot.py | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/bot.py b/src/bot.py index 16e1320..1d4ee36 100644 --- a/src/bot.py +++ b/src/bot.py @@ -70,6 +70,7 @@ class Music(commands.Cog): def _next(self): """Trigger playback of next song.""" + self.logger.info("Song finished. Triggering playback of next song") self._queue.task_done() self._current_skip_message = None if self._queue_lock.locked(): @@ -79,12 +80,16 @@ class Music(commands.Cog): async def _handle_playback(self): while True: try: + self.logger.info("Waiting for queue lock to acquire ...") await self._queue_lock.acquire() + self.logger.info("Queue lock acquired! Waiting for song queue to return a song ...") ctx, song = await self._queue.get() + self.logger.info("Queue returned a song!") if ctx.voice_client is None: # Bot is no longer in a voice channel. # This could be the case because a stop command was issued. # We will skip this (and possibly all remaining songs) in the queue + self.logger.info('Bot is no longer in a voice channel. Skipping song "%s".', song.title) self._next() continue audio = discord.FFmpegPCMAudio(song.audio_url, **self._ffmpeg_options) @@ -93,6 +98,7 @@ class Music(commands.Cog): if err: self.logger.error("Player error: %s", err) self._next() + self.logger.info('Now playing song "%s"', song.title) ctx.voice_client.play(audio, after=after) embed = NowPlayingMessage(title=song.title, url=song.webpage_url) msg = await ctx.send(embed=embed) @@ -133,6 +139,7 @@ class Music(commands.Cog): audio_url=data.get('url'), webpage_url=data.get('webpage_url') ) + self.logger.info('Qeueing song: title="%s", audio_url=%s, webpage_url=%s', song.title, song.audio_url, song.webpage_url) await self._queue.put((ctx, song)) if ctx.voice_client.is_playing(): embed = QueuedMessage(title=song.title, url=song.webpage_url) @@ -144,6 +151,7 @@ class Music(commands.Cog): raise commands.CommandError("No song playing") # This skips to next song because the bot does not differentiate between # a song stopping because it is finished or because it was manually stopped. + self.logger.info("Skipping song") voice_client.stop() @commands.command() @@ -153,13 +161,16 @@ class Music(commands.Cog): @commands.command() async def stop(self, ctx): + self.logger.info("Stopping playback") await ctx.voice_client.disconnect() @play.before_invoke async def ensure_voice(self, ctx): if ctx.voice_client is None: if ctx.author.voice: + self.logger.info("Connecting to voice channel ...") await ctx.author.voice.channel.connect() + self.logger.info("Connected") else: raise commands.CommandError("Author not connected to a voice channel") From 7905d7d3edddd46c8d32c20c64ecee20744e68e4 Mon Sep 17 00:00:00 2001 From: ekzyis Date: Thu, 4 Nov 2021 01:45:48 +0100 Subject: [PATCH 3/3] Remove end of sentence punctuation for log consistency --- src/bot.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bot.py b/src/bot.py index 1d4ee36..ac22c24 100644 --- a/src/bot.py +++ b/src/bot.py @@ -89,7 +89,7 @@ class Music(commands.Cog): # Bot is no longer in a voice channel. # This could be the case because a stop command was issued. # We will skip this (and possibly all remaining songs) in the queue - self.logger.info('Bot is no longer in a voice channel. Skipping song "%s".', song.title) + self.logger.info('Bot is no longer in a voice channel. Skipping song "%s"', song.title) self._next() continue audio = discord.FFmpegPCMAudio(song.audio_url, **self._ffmpeg_options)