1
0
Fork 0
mirror of synced 2024-05-19 20:12:30 +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): elif isinstance(error, commands.MissingRequiredArgument):
await ctx.message.channel.send(error) await ctx.message.channel.send(error)
else: else:
now = datetime.datetime.now() if isinstance(bot.error_channel, int):
with open("error_log", 'a') as f: bot.error_channel = bot.get_channel(bot.error_channel)
print("In server '{0.message.guild}' at {1}\nFull command: `{0.message.content}`".format(ctx, str(now)), elif bot.error_channel is None:
file=f) now = datetime.datetime.now()
traceback.print_tb(error.__traceback__, file=f) with open("error_log", 'a') as f:
print('{0.__class__.__name__}: {0}'.format(error), file=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: except discord.HTTPException:
pass pass

View file

@ -50,6 +50,8 @@ patreon_link = global_config.get('patreon_link', None)
# The client ID/secret for spotify # The client ID/secret for spotify
spotify_id = global_config.get("spotify_id", None) spotify_id = global_config.get("spotify_id", None)
spotify_secret = global_config.get("spotify_secret", 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 # The extensions to load
extensions = [ extensions = [