modified: bot.py
This commit is contained in:
80
bot.py
80
bot.py
@@ -1991,7 +1991,7 @@ async def modhelp(ctx):
|
||||
embed.add_field(
|
||||
name="👮 Moderator Commands (Level 5+)",
|
||||
value=(
|
||||
"`/warn <user> [reason | message_id]` - Warn a user (with optional message reference)\n"
|
||||
"`/warn <user> [reason] [message_id]` - Warn a user (with optional message reference)\n"
|
||||
"`/mute <user> <duration> [reason]` - Mute a user temporarily\n"
|
||||
"`/unmute <user>` - 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)
|
||||
# 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
|
||||
|
||||
# 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
|
||||
# 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)
|
||||
|
||||
except ValueError:
|
||||
await ctx.send("❌ Invalid message ID format. Use: `/warn @user reason | 1234567890123456789`", ephemeral=True)
|
||||
return
|
||||
# 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(
|
||||
|
||||
Reference in New Issue
Block a user