modified: bot.py

This commit is contained in:
SimolZimol
2025-09-28 21:23:50 +02:00
parent 4e587a2cc5
commit a9c531c395

37
bot.py
View File

@@ -3406,16 +3406,24 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
async def send_response(content=None, embed=None, ephemeral=False, file=None): async def send_response(content=None, embed=None, ephemeral=False, file=None):
try: try:
if is_slash_command: if is_slash_command:
if hasattr(ctx, 'followup') and ctx.followup:
await ctx.followup.send(content=content, embed=embed, ephemeral=ephemeral, file=file) await ctx.followup.send(content=content, embed=embed, ephemeral=ephemeral, file=file)
elif hasattr(ctx, 'response') and not ctx.response.is_done():
await ctx.response.send_message(content=content, embed=embed, ephemeral=ephemeral, file=file)
else:
await ctx.send(content=content, embed=embed, file=file)
else: else:
await ctx.send(content=content, embed=embed, file=file) await ctx.send(content=content, embed=embed, file=file)
except Exception as e: except Exception as e:
logger.error(f"Error sending response: {e}") logger.error(f"Error sending response in warn command: {e}")
# Fallback to regular send if followup fails # Final fallback - try basic send
try: try:
await ctx.send(content=content, embed=embed, file=file) if embed:
except: await ctx.send(embed=embed)
pass elif content:
await ctx.send(content=content)
except Exception as fallback_error:
logger.error(f"Fallback send also failed: {fallback_error}")
try: try:
# Parse message ID and context range from reason if provided inline # Parse message ID and context range from reason if provided inline
@@ -3531,7 +3539,7 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
moderator_id=ctx.author.id, moderator_id=ctx.author.id,
reason=reason, reason=reason,
message_data=message_data, message_data=message_data,
message_id=message_id_int if message_id else None message_id=int(parsed_message_id) if parsed_message_id else None
) )
# Get guild settings for threshold checking # Get guild settings for threshold checking
@@ -3650,9 +3658,20 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
} }
if message_data: if message_data:
log_additional_info["Referenced Message"] = f"ID: {message_data['id']}" # Handle both old and new message_data formats
log_additional_info["Message Channel"] = f"<#{message_data['channel_id']}>" if isinstance(message_data, dict) and "main_message" in message_data:
if message_data['content']: main_msg = message_data.get("main_message")
if main_msg:
log_additional_info["Referenced Message"] = f"ID: {main_msg.get('id')}"
log_additional_info["Message Channel"] = f"<#{main_msg.get('channel_id')}>"
if main_msg.get('content'):
content_preview = main_msg['content'][:200] + "..." if len(main_msg['content']) > 200 else main_msg['content']
log_additional_info["Message Content"] = content_preview
else:
# Handle old format
log_additional_info["Referenced Message"] = f"ID: {message_data.get('id')}"
log_additional_info["Message Channel"] = f"<#{message_data.get('channel_id')}>"
if message_data.get('content'):
content_preview = message_data['content'][:200] + "..." if len(message_data['content']) > 200 else message_data['content'] content_preview = message_data['content'][:200] + "..." if len(message_data['content']) > 200 else message_data['content']
log_additional_info["Message Content"] = content_preview log_additional_info["Message Content"] = content_preview