From 31a40ab7e3d84656bb4497336800fb991012a008 Mon Sep 17 00:00:00 2001 From: SimolZimol <70102430+SimolZimol@users.noreply.github.com> Date: Tue, 19 Aug 2025 23:44:02 +0200 Subject: [PATCH] modified: bot.py --- bot.py | 84 +++++++++++++++++++++++++++++++++++++++++----------------- 1 file changed, 60 insertions(+), 24 deletions(-) diff --git a/bot.py b/bot.py index 966d022..9fdd604 100644 --- a/bot.py +++ b/bot.py @@ -1991,7 +1991,7 @@ async def modhelp(ctx): embed.add_field( name="👮 Moderator Commands (Level 5+)", value=( - "`/warn [reason | message_id]` - Warn a user (with optional message reference)\n" + "`/warn [reason] [message_id]` - Warn a user (with optional message reference)\n" "`/mute [reason]` - Mute a user temporarily\n" "`/unmute ` - Manually unmute a user\n" "`/modinfo [user]` - View comprehensive user information\n" @@ -2053,6 +2053,7 @@ async def modhelp(ctx): "`10m` = 10 minutes, `1h` = 1 hour, `2d` = 2 days\n\n" "**Warning with message reference:**\n" "`/warn @user Inappropriate behavior | 1234567890123456789`\n" + "`/warn @user Bad language 1234567890123456789`\n" "The message will be saved even if deleted later." ), inline=False @@ -2943,39 +2944,74 @@ async def warn(ctx, user: discord.User, *, reason_and_message: str = "No reason Usage: /warn @user Inappropriate behavior /warn @user Spam messages | 1234567890123456789 + /warn @user Bad behavior 1234567890123456789 - Format: reason | message_id (optional) + Format: reason | message_id OR reason message_id (message_id optional) """ try: - # Parse reason and optional message ID - reason_parts = reason_and_message.split(" | ") - reason = reason_parts[0].strip() + # Parse reason and optional message ID - support multiple formats + reason = reason_and_message.strip() message_id = None message_data = None - if len(reason_parts) > 1: - try: - message_id = int(reason_parts[1].strip()) - # Try to get message data from current channel first - message_data = await get_message_data(ctx.channel, message_id) - - # If not found in current channel, try other channels the bot can access - if message_data is None: - for channel in ctx.guild.text_channels: - try: - message_data = await get_message_data(channel, message_id) - if message_data is not None: - break - except discord.Forbidden: - continue - - except ValueError: - await ctx.send("❌ Invalid message ID format. Use: `/warn @user reason | 1234567890123456789`", ephemeral=True) - return + # Method 1: Check for " | " separator + if " | " in reason_and_message: + reason_parts = reason_and_message.split(" | ") + reason = reason_parts[0].strip() + if len(reason_parts) > 1: + try: + message_id = int(reason_parts[1].strip()) + except ValueError: + pass + else: + # Method 2: Check if last word is a valid message ID (18-19 digits) + words = reason_and_message.strip().split() + if len(words) > 1: + last_word = words[-1] + # Discord message IDs are 18-19 digits long + if last_word.isdigit() and 17 <= len(last_word) <= 20: + try: + message_id = int(last_word) + # Remove the message ID from reason + reason = " ".join(words[:-1]).strip() + except ValueError: + pass + + # Try to get message data if message ID was found + if message_id: + # Try to get message data from current channel first + message_data = await get_message_data(ctx.channel, message_id) + + # If not found in current channel, try other channels the bot can access + if message_data is None: + for channel in ctx.guild.text_channels: + try: + message_data = await get_message_data(channel, message_id) + if message_data is not None: + break + except discord.Forbidden: + continue # Load moderator data mod_data = await load_user_data(ctx.author.id, ctx.guild.id) + # Debug: Show parsed information (for testing) + debug_info = f"**Parsed Information:**\n" + debug_info += f"Reason: `{reason}`\n" + if message_id: + debug_info += f"Message ID: `{message_id}`\n" + debug_info += f"Message Found: {'✅' if message_data else '❌'}" + else: + debug_info += "No Message ID provided" + + # Send debug info as ephemeral message + debug_embed = discord.Embed( + title="🔍 Debug Information", + description=debug_info, + color=0x3498db + ) + await ctx.send(embed=debug_embed, ephemeral=True) + # Check moderation rights if not check_moderation_permission(mod_data["permission"]): embed = discord.Embed(