From 26369f114a1c220c106fac4df24a3c74ec100880 Mon Sep 17 00:00:00 2001 From: xenofem Date: Mon, 16 Nov 2020 18:27:25 -0500 Subject: [PATCH] better exception handling, notify in discord on permission errors --- data_expunged.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/data_expunged.py b/data_expunged.py index 92f06e9..84d4de6 100644 --- a/data_expunged.py +++ b/data_expunged.py @@ -26,19 +26,23 @@ async def on_message(message): f = await a.to_file() f.filename = 'SPOILER_' + f.filename attachments.append(f) - except (discord.HTTPException, discord.Forbidden, discord.NotFound) as e: + except discord.DiscordException as e: print('error reading attachments: {0}'.format(e), file=sys.stderr) return try: await message.channel.send("{0} says: {1}".format(message.author.mention, message.content), files=attachments) - except (discord.HTTPException, discord.Forbidden, discord.InvalidArgument) as e: + except discord.DiscordException as e: print('error sending message: {0}'.format(e), file=sys.stderr) return try: await message.delete() - except (discord.HTTPException, discord.Forbidden, discord.NotFound) as e: + except discord.Forbidden as e: + print('error deleting message: {0}'.format(e)) + await message.channel.send("I can't delete the original unspoiled message because I don't have the permissions I need. Admins, please make sure I have the Manage Messages permission in all channels where people want to use me.") + return + except discord.DiscordException as e: print('error deleting message: {0}'.format(e)) return elif mentions_me(message):