modified: bot.py

This commit is contained in:
SimolZimol
2025-11-07 20:02:13 +01:00
parent 8ba7a1bf98
commit 618819707c

46
bot.py
View File

@@ -4756,9 +4756,9 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
Note: context_range parameter only works when message_id is also provided! Note: context_range parameter only works when message_id is also provided!
""" """
# Check if it's a slash command and defer if needed # Check if it's a slash command and defer if needed (skip defer for silent mode)
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
if is_slash_command: if is_slash_command and not silent:
await ctx.defer() await ctx.defer()
# Helper function for sending responses # Helper function for sending responses
@@ -5010,7 +5010,7 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
# Send response based on silent mode # Send response based on silent mode
if silent: if silent:
# Silent mode: ephemeral response to moderator at command location # Silent mode: ephemeral response to moderator only
silent_embed = discord.Embed( silent_embed = discord.Embed(
title="🔇 Silent Warning Issued", title="🔇 Silent Warning Issued",
description=f"{user.mention} has been warned silently.", description=f"{user.mention} has been warned silently.",
@@ -5028,24 +5028,31 @@ 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_footer(text=f"Silent Mode • User ID: {user.id}")
silent_embed.set_thumbnail(url=user.display_avatar.url) silent_embed.set_thumbnail(url=user.display_avatar.url)
# Force ephemeral response regardless of command type # Send ephemeral response - force it to be ephemeral
try:
if is_slash_command: if is_slash_command:
if hasattr(ctx, 'followup') and ctx.followup: if hasattr(ctx, 'followup') and ctx.followup:
await ctx.followup.send(embed=silent_embed, ephemeral=True) await ctx.followup.send(embed=silent_embed, ephemeral=True)
elif 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)
else: else:
# Fallback for slash commands without proper response # If somehow we get here, try a fallback
await ctx.send(embed=silent_embed, ephemeral=True) await ctx.send(embed=silent_embed, delete_after=30)
else: else:
# For prefix commands, send ephemeral-like message (delete after short time) # For prefix commands, send and delete quickly
msg = await ctx.send(embed=silent_embed) msg = await ctx.send(embed=silent_embed)
# Auto-delete after 30 seconds for prefix commands
await asyncio.sleep(30) await asyncio.sleep(30)
try: try:
await msg.delete() await msg.delete()
except: except:
pass pass
except Exception as e:
logger.error(f"Error sending silent warning response: {e}")
# Last resort fallback
try:
await ctx.send(f"⚠️ {user.mention} has been warned silently. Check DMs for details.", delete_after=10)
except:
pass
else: else:
# Normal mode: public response # Normal mode: public response
@@ -6317,9 +6324,9 @@ async def mute(ctx, user: discord.User, duration: str, reason: str = "No reason
Note: context_range parameter only works when message_id is also provided! Note: context_range parameter only works when message_id is also provided!
""" """
# Check if it's a slash command and defer if needed # Check if it's a slash command and defer if needed (skip defer for silent mode)
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
if is_slash_command: if is_slash_command and not silent:
await ctx.defer() await ctx.defer()
# Helper function for sending responses # Helper function for sending responses
@@ -6586,7 +6593,7 @@ async def mute(ctx, user: discord.User, duration: str, reason: str = "No reason
# Send response based on silent mode # Send response based on silent mode
if silent: if silent:
# Silent mode: ephemeral response to moderator at command location # Silent mode: ephemeral response to moderator only
silent_embed = discord.Embed( silent_embed = discord.Embed(
title="🔇 Silent Mute Applied", title="🔇 Silent Mute Applied",
description=f"{user.mention} has been muted silently.", description=f"{user.mention} has been muted silently.",
@@ -6605,24 +6612,31 @@ async def mute(ctx, user: discord.User, duration: str, reason: str = "No reason
silent_embed.set_footer(text=f"Silent Mode • User ID: {user.id} | Use /viewmute {mute_id} for details") silent_embed.set_footer(text=f"Silent Mode • User ID: {user.id} | Use /viewmute {mute_id} for details")
silent_embed.set_thumbnail(url=user.display_avatar.url) silent_embed.set_thumbnail(url=user.display_avatar.url)
# Force ephemeral response regardless of command type # Send ephemeral response - force it to be ephemeral
try:
if is_slash_command: if is_slash_command:
if hasattr(ctx, 'followup') and ctx.followup: if hasattr(ctx, 'followup') and ctx.followup:
await ctx.followup.send(embed=silent_embed, ephemeral=True) await ctx.followup.send(embed=silent_embed, ephemeral=True)
elif 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)
else: else:
# Fallback for slash commands without proper response # If somehow we get here, try a fallback
await ctx.send(embed=silent_embed, ephemeral=True) await ctx.send(embed=silent_embed, delete_after=30)
else: else:
# For prefix commands, send ephemeral-like message (delete after short time) # For prefix commands, send and delete quickly
msg = await ctx.send(embed=silent_embed) msg = await ctx.send(embed=silent_embed)
# Auto-delete after 30 seconds for prefix commands
await asyncio.sleep(30) await asyncio.sleep(30)
try: try:
await msg.delete() await msg.delete()
except: except:
pass pass
except Exception as e:
logger.error(f"Error sending silent mute response: {e}")
# Last resort fallback
try:
await ctx.send(f"🔇 {user.mention} has been muted silently for {duration}. Check DMs for details.", delete_after=10)
except:
pass
else: else:
# Normal mode: public response # Normal mode: public response