diff --git a/bot.py b/bot.py index c66eae1..3825210 100644 --- a/bot.py +++ b/bot.py @@ -2933,17 +2933,17 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess await ctx.defer() # Helper function for sending responses - async def send_response(content=None, embed=None, ephemeral=False): + async def send_response(content=None, embed=None, ephemeral=False, file=None): try: if is_slash_command: - await ctx.followup.send(content=content, embed=embed, ephemeral=ephemeral) + await ctx.followup.send(content=content, embed=embed, ephemeral=ephemeral, file=file) else: - await ctx.send(content=content, embed=embed) + await ctx.send(content=content, embed=embed, file=file) except Exception as e: logger.error(f"Error sending response: {e}") # Fallback to regular send if followup fails try: - await ctx.send(content=content, embed=embed) + await ctx.send(content=content, embed=embed, file=file) except: pass @@ -3506,6 +3506,21 @@ async def viewwarn(ctx, warning_id: int): if is_slash_command: await ctx.defer() + # Helper function for sending responses + async def send_response(content=None, embed=None, ephemeral=False, file=None): + try: + if is_slash_command: + await ctx.followup.send(content=content, embed=embed, ephemeral=ephemeral, file=file) + else: + await ctx.send(content=content, embed=embed, file=file) + except Exception as e: + logger.error(f"Error sending response: {e}") + # Fallback to regular send if followup fails + try: + await ctx.send(content=content, embed=embed, file=file) + except: + pass + try: # Load moderator data mod_data = await load_user_data(ctx.author.id, ctx.guild.id) @@ -3517,10 +3532,7 @@ async def viewwarn(ctx, warning_id: int): description="You need moderation permissions (Level 5 or higher) to use this command.", color=0xff0000 ) - if is_slash_command: - await ctx.followup.send(embed=embed, ephemeral=True) - else: - await ctx.send(embed=embed) + await send_response(embed=embed, ephemeral=True) return # Get warning details from database @@ -3546,10 +3558,7 @@ async def viewwarn(ctx, warning_id: int): description=f"No warning with ID {warning_id} found in this server.", color=0xff0000 ) - if is_slash_command: - await ctx.followup.send(embed=embed, ephemeral=True) - else: - await ctx.send(embed=embed) + await send_response(embed=embed, ephemeral=True) return # Parse result @@ -3614,10 +3623,7 @@ async def viewwarn(ctx, warning_id: int): # Send image separately if it's the first attachment if i == 0: - if is_slash_command: - await ctx.followup.send(f"📎 **Attachment from Warning {warning_id}:**", file=file) - else: - await ctx.send(f"📎 **Attachment from Warning {warning_id}:**", file=file) + await send_response(content=f"📎 **Attachment from Warning {warning_id}:**", file=file) except Exception as e: logger.warning(f"Could not display attachment: {e}") @@ -3631,10 +3637,7 @@ async def viewwarn(ctx, warning_id: int): embed.set_thumbnail(url=warned_user.display_avatar.url) embed.set_footer(text=f"Warning ID: {warning_id} | Guild: {ctx.guild.name}") - if is_slash_command: - await ctx.followup.send(embed=embed) - else: - await ctx.send(embed=embed) + await send_response(embed=embed) finally: if cursor: @@ -3649,10 +3652,7 @@ async def viewwarn(ctx, warning_id: int): description="An error occurred while retrieving warning details. Please try again.", color=0xff0000 ) - if is_slash_command: - await ctx.followup.send(embed=embed) - else: - await ctx.send(embed=embed) + await send_response(embed=embed) @client.hybrid_command() async def mute(ctx, user: discord.User, duration: str, *, reason: str = "No reason provided"):