modified: bot.py

This commit is contained in:
SimolZimol
2025-11-07 23:11:48 +01:00
parent 9bc222659d
commit 99a04b9a6b

57
bot.py
View File

@@ -5014,7 +5014,7 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
# Send response based on silent mode
if silent:
# Silent mode: ephemeral response to moderator only
# Silent mode: create special silent embed and send as ephemeral
silent_embed = discord.Embed(
title="🔇 Silent Warning Issued",
description=f"{user.mention} has been warned silently.",
@@ -5032,51 +5032,20 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
silent_embed.set_footer(text=f"Silent Mode • User ID: {user.id}")
silent_embed.set_thumbnail(url=user.display_avatar.url)
# Send ephemeral response - use followup since we deferred
try:
if is_slash_command:
# Since we deferred with ephemeral=silent, use followup
# Make sure followup is available and properly initialized
if hasattr(ctx, 'followup') and ctx.followup is not None:
await ctx.followup.send(embed=silent_embed, ephemeral=True)
logger.info(f"Silent warning sent via ctx.followup.send (ephemeral)")
elif hasattr(ctx, 'interaction') and ctx.interaction:
# Direct interaction followup as fallback
await ctx.interaction.followup.send(embed=silent_embed, ephemeral=True)
logger.info(f"Silent warning sent via ctx.interaction.followup.send (ephemeral)")
else:
logger.error(f"Silent warning failed: No followup available - ctx.followup: {getattr(ctx, 'followup', None)}")
raise Exception("No followup available after defer")
# Send as ephemeral
if is_slash_command:
if hasattr(ctx, 'followup') and ctx.followup is not None:
await ctx.followup.send(embed=silent_embed, ephemeral=True)
logger.info(f"Silent warning sent via ctx.followup.send (ephemeral)")
elif hasattr(ctx, 'interaction') and ctx.interaction:
await ctx.interaction.followup.send(embed=silent_embed, ephemeral=True)
logger.info(f"Silent warning sent via ctx.interaction.followup.send (ephemeral)")
else:
# For prefix commands, we can't do true ephemeral, so log error instead
logger.error(f"Silent warning attempted with prefix command - not supported")
raise Exception("Silent mode only works with slash commands")
except Exception as e:
logger.error(f"Error sending silent warning response: {e}")
# Send error to mod log instead of fallback message
try:
await log_moderation_action(
guild=ctx.guild,
action_type="warning_error",
moderator=ctx.author,
target_user=user,
reason=f"Silent warning issued but ephemeral response failed: {str(e)}",
additional_info={
"Original Reason": reason,
"Warning ID": str(warning_id) if warning_id else "N/A",
"Error Details": str(e),
"Command Type": "Slash" if is_slash_command else "Prefix",
"Fallback": "User received DM notification normally"
}
)
except Exception as log_error:
logger.error(f"Failed to log silent warning error: {log_error}")
# Silent mode is complete - exit here to prevent normal logging/responses
return
logger.error(f"Silent warning failed: No followup available")
else:
logger.error(f"Silent warning attempted with prefix command - not supported")
else:
# Normal mode: public response
# Normal mode: send public response
await send_response(embed=embed)
# Log the warning action