Catch exceptions in message handler and not command dispatch. Closes #18

This commit is contained in:
Ske
2018-09-15 14:52:24 +02:00
parent 22b206c562
commit fd67945660
3 changed files with 43 additions and 32 deletions

View File

@@ -139,26 +139,6 @@ import pluralkit.bot.commands.switch_commands
import pluralkit.bot.commands.system_commands
async def log_error_in_channel(ctx: CommandContext):
channel_id = os.environ["LOG_CHANNEL"]
if not channel_id:
return
channel = ctx.client.get_channel(channel_id)
embed = discord.Embed()
embed.colour = discord.Colour.dark_red()
embed.title = ctx.message.content
embed.set_footer(text="Sender: {}#{} | Server: {} | Channel: {}".format(
ctx.message.author.name, ctx.message.author.discriminator,
ctx.message.server.id if ctx.message.server else "(DMs)",
ctx.message.channel.id
))
await ctx.client.send_message(channel, "```python\n{}```".format(traceback.format_exc()), embed=embed)
async def run_command(ctx: CommandContext, func):
try:
result = await func(ctx)
@@ -166,10 +146,6 @@ async def run_command(ctx: CommandContext, func):
await ctx.reply(embed=result.to_embed())
except CommandError as e:
await ctx.reply(embed=e.to_embed())
except Exception as e:
logger.exception("Exception while dispatching command")
await log_error_in_channel(ctx)
async def command_dispatch(client: discord.Client, message: discord.Message, conn) -> bool: