1
0
Fork 0
mirror of synced 2024-05-07 06:02:24 +12:00

Add a way to send errors to an error channel instead of an error log

This commit is contained in:
Phxntxm 2019-11-19 17:13:10 -06:00
parent 8bff707037
commit 0179f3913c
2 changed files with 17 additions and 6 deletions

21
bot.py
View file

@ -91,12 +91,21 @@ async def on_command_error(ctx, error):
elif isinstance(error, commands.MissingRequiredArgument):
await ctx.message.channel.send(error)
else:
now = datetime.datetime.now()
with open("error_log", 'a') as f:
print("In server '{0.message.guild}' at {1}\nFull command: `{0.message.content}`".format(ctx, str(now)),
file=f)
traceback.print_tb(error.__traceback__, file=f)
print('{0.__class__.__name__}: {0}'.format(error), file=f)
if isinstance(bot.error_channel, int):
bot.error_channel = bot.get_channel(bot.error_channel)
elif bot.error_channel is None:
now = datetime.datetime.now()
with open("error_log", 'a') as f:
print("In server '{0.message.guild}' at {1}\n"
"Full command: `{0.message.content}`".format(ctx, str(now)), file=f)
traceback.print_tb(error.__traceback__, file=f)
print('{0.__class__.__name__}: {0}'.format(error), file=f)
else:
await bot.error_channel.send(f"""```
Command = {discord.utils.escape_markdown(ctx.message.clean_content).strip()}
{''.join(traceback.format_tb(error.__traceback__)).strip()}
{error.__class__.__name__}: {error.strip()}
```""")
except discord.HTTPException:
pass

View file

@ -50,6 +50,8 @@ patreon_link = global_config.get('patreon_link', None)
# The client ID/secret for spotify
spotify_id = global_config.get("spotify_id", None)
spotify_secret = global_config.get("spotify_secret", None)
# Error channel to send uncaught exceptions to
error_channel = global_config.get("error_channel", None)
# The extensions to load
extensions = [