Suppress error chain in error handlers

This commit is contained in:
eek7574 2022-11-28 17:30:44 +00:00
parent 0c78683090
commit e0766fef21
5 changed files with 11 additions and 13 deletions

View file

@ -430,7 +430,7 @@ class AssignmentsCog(commands.Cog):
super().__init__(timeout=300)
async def interaction_check(self, interaction: discord.Interaction) -> bool:
return interaction.user == ctx.author
return interaction.user == ctx.user
async def on_timeout(self) -> None:
await self.message.delete(delay=0.1)

View file

@ -1,7 +1,6 @@
import discord
from discord.ext import commands
from utils import Student, get_or_none, BannedStudentID
import orm
class Mod(commands.Cog):
@ -24,7 +23,7 @@ class Mod(commands.Cog):
associated_account=member.id,
)
await member.ban(reason=f"Banned ID {ban.student_id} by {ctx.author}")
await member.ban(reason=f"Banned ID {ban.student_id} by {ctx.user}")
return await ctx.respond(
f"\N{white heavy check mark} Banned {ban.student_id} (and {member.mention})", ephemeral=True
)
@ -44,7 +43,7 @@ class Mod(commands.Cog):
return await ctx.respond(f"\N{white heavy check mark} Unbanned {student_id}. No user to unban.")
else:
try:
await ctx.guild.unban(discord.Object(user_id), reason=f"Unbanned by {ctx.author}")
await ctx.guild.unban(discord.Object(user_id), reason=f"Unbanned by {ctx.user}")
except discord.HTTPException as e:
return await ctx.respond(
f"\N{white heavy check mark} Unbanned {student_id}. Failed to unban {user_id} - HTTP {e.status}."

View file

@ -1,6 +1,5 @@
import asyncio
import sys
from typing import Optional, Union, Dict, Callable
from typing import Optional, Union, Dict
import discord
from discord.ext import commands, tasks
@ -239,7 +238,7 @@ class TimeTableCog(commands.Cog):
date = datetime.now()
text = self.format_timetable_message(date)
view = TimeTableDaySwitcherView(ctx.author, self, date)
view = TimeTableDaySwitcherView(ctx.user, self, date)
view.update_buttons()
await ctx.respond(text, view=view)

View file

@ -14,19 +14,19 @@ class VerifyCog(commands.Cog):
"""Verifies or generates a verification code"""
try:
student: Student = await Student.objects.get(user_id=ctx.author.id)
student: Student = await Student.objects.get(user_id=ctx.user.id)
return await ctx.respond(f"\N{cross mark} You're already verified as {student.id}!", ephemeral=True)
except orm.NoMatch:
pass
role = discord.utils.find(lambda r: r.name.lower() == "verified", ctx.guild.roles)
channel = discord.utils.get(ctx.guild.text_channels, name="verify")
if role in ctx.author.roles:
if role in ctx.user.roles:
if role and role < ctx.me.top_role:
await ctx.author.remove_roles(role, reason=f"Auto de-verified")
await ctx.user.remove_roles(role, reason=f"Auto de-verified")
if channel:
try:
await ctx.author.send(
await ctx.user.send(
f"You have been automatically de-verified. Please re-verify by going to {channel.mention} "
f"and typing </verify:{ctx.command.id}>."
)

View file

@ -28,7 +28,7 @@ async def on_connect():
@bot.listen("on_application_command_error")
async def on_application_command_error(ctx: discord.ApplicationContext, error: Exception):
await ctx.respond("Application Command Error: `%r`" % error)
raise error
raise error from None
@bot.listen("on_command_error")
@ -36,7 +36,7 @@ async def on_command_error(ctx: commands.Context, error: Exception):
if isinstance(error, commands.CommandNotFound):
return
await ctx.reply("Command Error: `%r`" % error)
raise error
raise error from None
@bot.listen("on_application_command")