paginate error handling messages
This commit is contained in:
parent
4fa6b25971
commit
3d90376535
1 changed files with 38 additions and 16 deletions
|
@ -9,7 +9,7 @@ from contextlib import redirect_stdout
|
|||
|
||||
from disnake import Guild, Intents, Message
|
||||
from disnake.ext import commands
|
||||
from disnake.ext.commands import Bot
|
||||
from disnake.ext.commands import Bot, Paginator
|
||||
from dotenv import find_dotenv, load_dotenv
|
||||
|
||||
from .db import run_db_migrations, setup_db
|
||||
|
@ -142,13 +142,19 @@ async def on_command_error(ctx, error):
|
|||
|
||||
log.error(error, exc_info=error)
|
||||
timestamp = int(ctx.message.created_at.timestamp())
|
||||
paginator = Paginator()
|
||||
ptraceback = "".join(traceback.format_exception(error))
|
||||
for line in ptraceback.split("\n"):
|
||||
paginator.add_line(line)
|
||||
await ctx.bot.owner.send(
|
||||
f"# Command Error Occurred: {error}\n\n"
|
||||
f"```\n{"".join(traceback.format_exception(error))}```\n\n"
|
||||
f"# Command Error Occurred: {error}\n"
|
||||
f"## Context\n"
|
||||
f"**From:** {ctx.author.mention} ({ctx.author.name})\n"
|
||||
f"<t:{timestamp}>, <t:{timestamp}:R> | [Jump to Command]({ctx.message.jump_url}) | <#{ctx.channel.id}>\n"
|
||||
f"## Traceback"
|
||||
)
|
||||
for page in paginator.pages:
|
||||
await ctx.bot.owner.send(page)
|
||||
await ctx.send(
|
||||
f"Error: {error}\n\n**Note:** Infinidoge (Developer) has already been sent a notification that an error occurred and will come investigate when available."
|
||||
)
|
||||
|
@ -156,18 +162,23 @@ async def on_command_error(ctx, error):
|
|||
|
||||
@bot.event
|
||||
async def on_error(event, *args, **kwargs):
|
||||
ptraceback = "".join(traceback.format_exc())
|
||||
pargs = pprint.pformat(args)
|
||||
pkwargs = pprint.pformat(kwargs)
|
||||
|
||||
try:
|
||||
paginator = Paginator()
|
||||
for line in traceback.format_exc().split("\n"):
|
||||
paginator.add_line(line)
|
||||
await bot.owner.send(
|
||||
f"# Error Occurred: Event `{event}`"
|
||||
f"```\n{ptraceback}```"
|
||||
f"## args"
|
||||
f"```\n{pargs}\n```"
|
||||
f"## kwargs"
|
||||
f"```\n{pkwargs}\n```"
|
||||
f"# Error Occurred: Event `{event[:100]}`\n"
|
||||
f"## args\n"
|
||||
f"```\n{pargs}\n```\n"
|
||||
f"## kwargs\n"
|
||||
f"```\n{pkwargs}\n```\n"
|
||||
f"## Traceback"
|
||||
)
|
||||
for page in paginator.pages:
|
||||
await bot.owner.send(page)
|
||||
except: # Don't want recursive errors
|
||||
pass
|
||||
|
||||
|
@ -226,7 +237,11 @@ async def admin_eval(ctx, *, body: str):
|
|||
ret = await func()
|
||||
except Exception:
|
||||
value = stdout.getvalue()
|
||||
await ctx.send("```py\n{}{}\n```".format(value, traceback.format_exc()))
|
||||
ret = traceback.format_exc()
|
||||
try:
|
||||
await ctx.message.add_reaction("\u2705")
|
||||
except:
|
||||
pass
|
||||
else:
|
||||
value = stdout.getvalue()
|
||||
try:
|
||||
|
@ -234,11 +249,18 @@ async def admin_eval(ctx, *, body: str):
|
|||
except:
|
||||
pass
|
||||
|
||||
if ret is None:
|
||||
paginator = Paginator(prefix="```py", suffix="```")
|
||||
if value:
|
||||
await ctx.send("```py\n{}\n```".format(value))
|
||||
else:
|
||||
await ctx.send("```py\n{}{}\n```".format(value, ret))
|
||||
for line in str(value).split("\n"):
|
||||
paginator.add_line(line)
|
||||
paginator.close_page()
|
||||
if ret:
|
||||
for line in str(ret).split("\n"):
|
||||
paginator.add_line(line)
|
||||
paginator.close_page()
|
||||
|
||||
for page in paginator.pages:
|
||||
await ctx.send(page)
|
||||
|
||||
|
||||
@bot.command()
|
||||
|
|
Loading…
Reference in a new issue