better exception handling, notify in discord on permission errors

This commit is contained in:
xenofem 2020-11-16 18:27:25 -05:00
parent 9fbd6173b3
commit 26369f114a

View file

@ -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):