From 0b33e226a65094467bfd4e750bb5fe085fff0b65 Mon Sep 17 00:00:00 2001 From: xenofem Date: Sun, 13 Sep 2020 17:09:55 -0400 Subject: [PATCH] notify on errors --- journal3.py | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/journal3.py b/journal3.py index 0d1701c..affbbe8 100644 --- a/journal3.py +++ b/journal3.py @@ -20,11 +20,16 @@ async def on_message(message): await message.channel.send('generating channel archive...') with io.StringIO() as buf: - async for m in message.channel.history(limit=None, oldest_first=True): - buf.write('@{0.author.name}#{0.author.discriminator} {0.created_at}\n{0.clean_content}\n\n'.format(m)) - buf.seek(0) - f = discord.File(buf, '{}_{}.txt'.format(message.channel.guild.name, message.channel.name)) - await message.channel.send('complete:', files=[f]) + try: + async for m in message.channel.history(limit=None, oldest_first=True): + buf.write('@{0.author.name}#{0.author.discriminator} {0.created_at}\n{0.clean_content}\n\n'.format(m)) + buf.seek(0) + f = discord.File(buf, '{}_{}.txt'.format(message.channel.guild.name, message.channel.name)) + await message.channel.send('complete:', files=[f]) + except discord.Forbidden: + await message.channel.send('Looks like I don\'t have the right permissions :( Please make sure I have the "Read Message History" and "Attach Files" permissions for this channel.') + except discord.DiscordException as e: + await message.channel.send("Something went wrong: {}".format(e)) with open('token') as f: token = f.read().strip()