mirror of
https://github.com/nexy7574/LCC-bot.git
synced 2024-09-19 18:16:34 +01:00
Suppress error chain in error handlers
This commit is contained in:
parent
0c78683090
commit
e0766fef21
5 changed files with 11 additions and 13 deletions
|
@ -430,7 +430,7 @@ class AssignmentsCog(commands.Cog):
|
||||||
super().__init__(timeout=300)
|
super().__init__(timeout=300)
|
||||||
|
|
||||||
async def interaction_check(self, interaction: discord.Interaction) -> bool:
|
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:
|
async def on_timeout(self) -> None:
|
||||||
await self.message.delete(delay=0.1)
|
await self.message.delete(delay=0.1)
|
||||||
|
|
|
@ -1,7 +1,6 @@
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands
|
from discord.ext import commands
|
||||||
from utils import Student, get_or_none, BannedStudentID
|
from utils import Student, get_or_none, BannedStudentID
|
||||||
import orm
|
|
||||||
|
|
||||||
|
|
||||||
class Mod(commands.Cog):
|
class Mod(commands.Cog):
|
||||||
|
@ -24,7 +23,7 @@ class Mod(commands.Cog):
|
||||||
associated_account=member.id,
|
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(
|
return await ctx.respond(
|
||||||
f"\N{white heavy check mark} Banned {ban.student_id} (and {member.mention})", ephemeral=True
|
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.")
|
return await ctx.respond(f"\N{white heavy check mark} Unbanned {student_id}. No user to unban.")
|
||||||
else:
|
else:
|
||||||
try:
|
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:
|
except discord.HTTPException as e:
|
||||||
return await ctx.respond(
|
return await ctx.respond(
|
||||||
f"\N{white heavy check mark} Unbanned {student_id}. Failed to unban {user_id} - HTTP {e.status}."
|
f"\N{white heavy check mark} Unbanned {student_id}. Failed to unban {user_id} - HTTP {e.status}."
|
||||||
|
|
|
@ -1,6 +1,5 @@
|
||||||
import asyncio
|
|
||||||
import sys
|
import sys
|
||||||
from typing import Optional, Union, Dict, Callable
|
from typing import Optional, Union, Dict
|
||||||
|
|
||||||
import discord
|
import discord
|
||||||
from discord.ext import commands, tasks
|
from discord.ext import commands, tasks
|
||||||
|
@ -239,7 +238,7 @@ class TimeTableCog(commands.Cog):
|
||||||
date = datetime.now()
|
date = datetime.now()
|
||||||
|
|
||||||
text = self.format_timetable_message(date)
|
text = self.format_timetable_message(date)
|
||||||
view = TimeTableDaySwitcherView(ctx.author, self, date)
|
view = TimeTableDaySwitcherView(ctx.user, self, date)
|
||||||
view.update_buttons()
|
view.update_buttons()
|
||||||
await ctx.respond(text, view=view)
|
await ctx.respond(text, view=view)
|
||||||
|
|
||||||
|
|
|
@ -14,19 +14,19 @@ class VerifyCog(commands.Cog):
|
||||||
"""Verifies or generates a verification code"""
|
"""Verifies or generates a verification code"""
|
||||||
|
|
||||||
try:
|
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)
|
return await ctx.respond(f"\N{cross mark} You're already verified as {student.id}!", ephemeral=True)
|
||||||
except orm.NoMatch:
|
except orm.NoMatch:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
role = discord.utils.find(lambda r: r.name.lower() == "verified", ctx.guild.roles)
|
role = discord.utils.find(lambda r: r.name.lower() == "verified", ctx.guild.roles)
|
||||||
channel = discord.utils.get(ctx.guild.text_channels, name="verify")
|
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:
|
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:
|
if channel:
|
||||||
try:
|
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"You have been automatically de-verified. Please re-verify by going to {channel.mention} "
|
||||||
f"and typing </verify:{ctx.command.id}>."
|
f"and typing </verify:{ctx.command.id}>."
|
||||||
)
|
)
|
||||||
|
|
4
main.py
4
main.py
|
@ -28,7 +28,7 @@ async def on_connect():
|
||||||
@bot.listen("on_application_command_error")
|
@bot.listen("on_application_command_error")
|
||||||
async def on_application_command_error(ctx: discord.ApplicationContext, error: Exception):
|
async def on_application_command_error(ctx: discord.ApplicationContext, error: Exception):
|
||||||
await ctx.respond("Application Command Error: `%r`" % error)
|
await ctx.respond("Application Command Error: `%r`" % error)
|
||||||
raise error
|
raise error from None
|
||||||
|
|
||||||
|
|
||||||
@bot.listen("on_command_error")
|
@bot.listen("on_command_error")
|
||||||
|
@ -36,7 +36,7 @@ async def on_command_error(ctx: commands.Context, error: Exception):
|
||||||
if isinstance(error, commands.CommandNotFound):
|
if isinstance(error, commands.CommandNotFound):
|
||||||
return
|
return
|
||||||
await ctx.reply("Command Error: `%r`" % error)
|
await ctx.reply("Command Error: `%r`" % error)
|
||||||
raise error
|
raise error from None
|
||||||
|
|
||||||
|
|
||||||
@bot.listen("on_application_command")
|
@bot.listen("on_application_command")
|
||||||
|
|
Loading…
Reference in a new issue