Skip to content

Commit

Permalink
Some error messages are now logged rather than silenced.
Browse files Browse the repository at this point in the history
  • Loading branch information
rhliang committed Oct 10, 2022
1 parent 6d93b9b commit 5215e6b
Showing 1 changed file with 33 additions and 10 deletions.
43 changes: 33 additions & 10 deletions bot/raid_fyi_cog.py
Original file line number Diff line number Diff line change
Expand Up @@ -1016,8 +1016,12 @@ async def guild_logging_coro(*args, **kwargs):
async def before_clean_up_fyis(self):
await self.bot.wait_until_ready()

@staticmethod
async def cleanup_fc_messages(delay: int, bot_reply: discord.Message, original_message: discord.Message):
async def cleanup_fc_messages(
self,
delay: int,
bot_reply: discord.Message,
original_message: discord.Message,
):
"""
Helper to clean up the messages after a user calls the friend code commands.
:param delay:
Expand All @@ -1026,14 +1030,33 @@ async def cleanup_fc_messages(delay: int, bot_reply: discord.Message, original_m
:return:
"""
await asyncio.sleep(delay)
try:
await bot_reply.delete()
except (discord.NotFound, discord.HTTPException):
pass
try:
await original_message.delete()
except (discord.NotFound, discord.HTTPException):
pass
log_error_message: str = ""
for msg in (bot_reply, original_message):
try:
await msg.delete()
except discord.NotFound:
pass
except discord.HTTPException as exc:
log_error_message = (
f"The bot failed to delete a friend code command, "
f"perhaps due to network issues.\n"
f"Error message:\n"
f"{exc}"
)
except discord.Forbidden as exc:
log_error_message = (
f"The bot failed to delete a friend code command "
f"perhaps because it lacks the appropriate permissions. "
f"Check the bot permissions in the channels where these "
f"commands are used.\n"
f"Error message:\n"
f"{exc}"
)

if log_error_message != "" and self.logging_cog is not None:
await self.logging_cog.log_to_channel(
original_message.guild, log_error_message
)

@command(
help="Associate a friend code with your Discord account.",
Expand Down

0 comments on commit 5215e6b

Please sign in to comment.