notify on errors

This commit is contained in:
xenofem 2020-09-13 17:09:55 -04:00
parent 4047b52c7d
commit 0b33e226a6

View file

@ -20,11 +20,16 @@ async def on_message(message):
await message.channel.send('generating channel archive...')
with io.StringIO() as buf:
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()