modified: bot.py
This commit is contained in:
44
bot.py
44
bot.py
@@ -4756,12 +4756,14 @@ 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!
|
||||
"""
|
||||
# Check if it's a slash command and defer if needed (skip defer for silent mode)
|
||||
# Check if it's a slash command and defer if needed
|
||||
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
|
||||
if silent:
|
||||
logger.info(f"Silent warn command - is_slash_command: {is_slash_command}, has interaction: {hasattr(ctx, 'interaction')}, interaction value: {getattr(ctx, 'interaction', None)}")
|
||||
if is_slash_command and not silent:
|
||||
await ctx.defer()
|
||||
|
||||
# For slash commands, always defer to ensure we have a response method
|
||||
if is_slash_command:
|
||||
await ctx.defer(ephemeral=silent) # Defer as ephemeral if silent mode
|
||||
|
||||
# Helper function for sending responses
|
||||
async def send_response(content=None, embed=None, ephemeral=False, file=None):
|
||||
@@ -5030,20 +5032,16 @@ 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 - force it to be ephemeral
|
||||
# Send ephemeral response - use followup since we deferred
|
||||
try:
|
||||
if is_slash_command:
|
||||
# For slash commands, use response.send_message directly for ephemeral
|
||||
if hasattr(ctx, 'response') and not ctx.response.is_done():
|
||||
await ctx.response.send_message(embed=silent_embed, ephemeral=True)
|
||||
logger.info(f"Silent warning sent via ctx.response.send_message (ephemeral)")
|
||||
elif hasattr(ctx, 'followup') and ctx.followup:
|
||||
# Since we deferred with ephemeral=silent, use followup
|
||||
if hasattr(ctx, 'followup') and ctx.followup:
|
||||
await ctx.followup.send(embed=silent_embed, ephemeral=True)
|
||||
logger.info(f"Silent warning sent via ctx.followup.send (ephemeral)")
|
||||
else:
|
||||
# This shouldn't happen for slash commands but log it
|
||||
logger.error(f"Silent warning failed: No valid response method available for slash command")
|
||||
raise Exception("No valid ephemeral response method available")
|
||||
logger.error(f"Silent warning failed: No followup available after defer")
|
||||
raise Exception("No followup available after defer")
|
||||
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")
|
||||
@@ -6342,10 +6340,12 @@ 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!
|
||||
"""
|
||||
# Check if it's a slash command and defer if needed (skip defer for silent mode)
|
||||
# Check if it's a slash command and defer if needed
|
||||
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
|
||||
if is_slash_command and not silent:
|
||||
await ctx.defer()
|
||||
|
||||
# For slash commands, always defer to ensure we have a response method
|
||||
if is_slash_command:
|
||||
await ctx.defer(ephemeral=silent) # Defer as ephemeral if silent mode
|
||||
|
||||
# Helper function for sending responses
|
||||
async def send_response(content=None, embed=None, ephemeral=False, file=None):
|
||||
@@ -6630,20 +6630,16 @@ 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_thumbnail(url=user.display_avatar.url)
|
||||
|
||||
# Send ephemeral response - force it to be ephemeral
|
||||
# Send ephemeral response - use followup since we deferred
|
||||
try:
|
||||
if is_slash_command:
|
||||
# For slash commands, use response.send_message directly for ephemeral
|
||||
if hasattr(ctx, 'response') and not ctx.response.is_done():
|
||||
await ctx.response.send_message(embed=silent_embed, ephemeral=True)
|
||||
logger.info(f"Silent mute sent via ctx.response.send_message (ephemeral)")
|
||||
elif hasattr(ctx, 'followup') and ctx.followup:
|
||||
# Since we deferred with ephemeral=silent, use followup
|
||||
if hasattr(ctx, 'followup') and ctx.followup:
|
||||
await ctx.followup.send(embed=silent_embed, ephemeral=True)
|
||||
logger.info(f"Silent mute sent via ctx.followup.send (ephemeral)")
|
||||
else:
|
||||
# This shouldn't happen for slash commands but log it
|
||||
logger.error(f"Silent mute failed: No valid response method available for slash command")
|
||||
raise Exception("No valid ephemeral response method available")
|
||||
logger.error(f"Silent mute failed: No followup available after defer")
|
||||
raise Exception("No followup available after defer")
|
||||
else:
|
||||
# For prefix commands, we can't do true ephemeral, so log error instead
|
||||
logger.error(f"Silent mute attempted with prefix command - not supported")
|
||||
|
||||
Reference in New Issue
Block a user