From 9584b34f8f62417b252e54d7b4302a1492943967 Mon Sep 17 00:00:00 2001 From: Sven Heidemann Date: Tue, 16 Nov 2021 20:48:53 +0100 Subject: [PATCH] Improved logging to message service --- src/gismo_core/service/message_service.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/src/gismo_core/service/message_service.py b/src/gismo_core/service/message_service.py index 73effd4..6a90d79 100644 --- a/src/gismo_core/service/message_service.py +++ b/src/gismo_core/service/message_service.py @@ -38,12 +38,14 @@ class MessageService(MessageServiceABC): async def send_channel_message(self, channel: discord.TextChannel, message: str): self._logger.debug(__name__, f'Try to send message {message} to channel {channel.id}') + msg = None try: - await self.delete_message(await channel.send(message)) + msg = await channel.send(message) except Exception as e: self._logger.error(__name__, f'Send message to channel {channel.id} failed', e) else: self._logger.info(__name__, f'Sent message to channel {channel.id}') + await self.delete_message(msg) async def send_dm_message(self, message: str, receiver: Union[discord.User, discord.Member]): self._logger.debug(__name__, f'Try to send message {message} to user {receiver.id}') @@ -61,12 +63,14 @@ class MessageService(MessageServiceABC): return self._logger.debug(__name__, f'Try to send message {message} to channel {ctx.channel.id}') + msg = None try: if isinstance(message, discord.File): - await self.delete_message(await ctx.send(file=message)) + msg = await ctx.send(file=message) else: - await self.delete_message(await ctx.send(message)) + msg = await ctx.send(message) except Exception as e: self._logger.error(__name__, f'Send message to channel {ctx.channel.id} failed', e) else: self._logger.info(__name__, f'Sent message to channel {ctx.channel.id}') + await self.delete_message(msg)