modified: bot.py

This commit is contained in:
SimolZimol
2025-11-07 20:12:48 +01:00
parent 618819707c
commit 338b77ddfd

56
bot.py
View File

@@ -5031,10 +5031,11 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
# Send ephemeral response - force it to be ephemeral # Send ephemeral response - force it to be ephemeral
try: try:
if is_slash_command: if is_slash_command:
if hasattr(ctx, 'followup') and ctx.followup: # For slash commands, use response.send_message directly for ephemeral
await ctx.followup.send(embed=silent_embed, ephemeral=True) if hasattr(ctx, 'response') and not ctx.response.is_done():
elif hasattr(ctx, 'response') and not ctx.response.is_done():
await ctx.response.send_message(embed=silent_embed, ephemeral=True) await ctx.response.send_message(embed=silent_embed, ephemeral=True)
elif hasattr(ctx, 'followup') and ctx.followup:
await ctx.followup.send(embed=silent_embed, ephemeral=True)
else: else:
# If somehow we get here, try a fallback # If somehow we get here, try a fallback
await ctx.send(embed=silent_embed, delete_after=30) await ctx.send(embed=silent_embed, delete_after=30)
@@ -5048,11 +5049,23 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
pass pass
except Exception as e: except Exception as e:
logger.error(f"Error sending silent warning response: {e}") logger.error(f"Error sending silent warning response: {e}")
# Last resort fallback # Send error to mod log instead of fallback message
try: try:
await ctx.send(f"⚠️ {user.mention} has been warned silently. Check DMs for details.", delete_after=10) await log_moderation_action(
except: guild=ctx.guild,
pass 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),
"Fallback": "User received DM notification normally"
}
)
except Exception as log_error:
logger.error(f"Failed to log silent warning error: {log_error}")
else: else:
# Normal mode: public response # Normal mode: public response
@@ -6615,10 +6628,11 @@ async def mute(ctx, user: discord.User, duration: str, reason: str = "No reason
# Send ephemeral response - force it to be ephemeral # Send ephemeral response - force it to be ephemeral
try: try:
if is_slash_command: if is_slash_command:
if hasattr(ctx, 'followup') and ctx.followup: # For slash commands, use response.send_message directly for ephemeral
await ctx.followup.send(embed=silent_embed, ephemeral=True) if hasattr(ctx, 'response') and not ctx.response.is_done():
elif hasattr(ctx, 'response') and not ctx.response.is_done():
await ctx.response.send_message(embed=silent_embed, ephemeral=True) await ctx.response.send_message(embed=silent_embed, ephemeral=True)
elif hasattr(ctx, 'followup') and ctx.followup:
await ctx.followup.send(embed=silent_embed, ephemeral=True)
else: else:
# If somehow we get here, try a fallback # If somehow we get here, try a fallback
await ctx.send(embed=silent_embed, delete_after=30) await ctx.send(embed=silent_embed, delete_after=30)
@@ -6632,11 +6646,25 @@ async def mute(ctx, user: discord.User, duration: str, reason: str = "No reason
pass pass
except Exception as e: except Exception as e:
logger.error(f"Error sending silent mute response: {e}") logger.error(f"Error sending silent mute response: {e}")
# Last resort fallback # Send error to mod log instead of fallback message
try: try:
await ctx.send(f"🔇 {user.mention} has been muted silently for {duration}. Check DMs for details.", delete_after=10) await log_moderation_action(
except: guild=ctx.guild,
pass action_type="mute_error",
moderator=ctx.author,
target_user=user,
reason=f"Silent mute issued but ephemeral response failed: {str(e)}",
duration=duration,
additional_info={
"Original Reason": reason,
"Mute ID": str(mute_id) if mute_id else "N/A",
"Duration": duration,
"Error Details": str(e),
"Fallback": "User received DM notification normally"
}
)
except Exception as log_error:
logger.error(f"Failed to log silent mute error: {log_error}")
else: else:
# Normal mode: public response # Normal mode: public response