Some commands have try-except, others don't. Some use exc_info=True, others don't.
Fix: Create error handling decorator:
from functools import wraps
def handle_command_errors(func): @wraps(func) async def wrapper(interaction: discord.Interaction, *args, **kwargs): try: return await func(interaction, *args, **kwargs) except Exception as e: logger.error(f"Error in {func.name}: {e}", exc_info=True) error_msg = "An unexpected error occurred. Please try again later." if not interaction.response.is_done(): await interaction.response.send_message(error_msg, ephemeral=True) else: await interaction.followup.send(error_msg, ephemeral=True) return wrapper
@client.tree.command(name="example") @handle_command_errors async def example(interaction: discord.Interaction): # Your code here
No dependencies set.
The note is not visible to the blocked user.
Some commands have try-except, others don't. Some use exc_info=True, others don't.
Fix: Create error handling decorator:
from functools import wraps
def handle_command_errors(func):
@wraps(func)
async def wrapper(interaction: discord.Interaction, *args, **kwargs):
try:
return await func(interaction, *args, **kwargs)
except Exception as e:
logger.error(f"Error in {func.name}: {e}", exc_info=True)
error_msg = "An unexpected error occurred. Please try again later."
if not interaction.response.is_done():
await interaction.response.send_message(error_msg, ephemeral=True)
else:
await interaction.followup.send(error_msg, ephemeral=True)
return wrapper
Usage:
@client.tree.command(name="example")
@handle_command_errors
async def example(interaction: discord.Interaction):
# Your code here