modified: bot.py

This commit is contained in:
SimolZimol
2025-08-21 18:13:29 +02:00
parent 5b9e771729
commit b27ff645ce

32
bot.py
View File

@@ -2976,8 +2976,10 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
Parameters: Parameters:
- user: The user to warn - user: The user to warn
- reason: Reason for the warning - reason: Reason for the warning
- message_id: Optional message ID to reference - message_id: Optional message ID to reference (required for context_range)
- context_range: Number of messages before/after to archive (default: 3, max: 25) - context_range: Number of messages before/after to archive (only works with message_id)
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
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
@@ -3006,7 +3008,7 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
# Check if reason ends with potential message ID and/or context range # Check if reason ends with potential message ID and/or context range
reason_words = reason.split() reason_words = reason.split()
parsed_message_id = message_id parsed_message_id = message_id
parsed_context_range = context_range parsed_context_range = 3 # Default context range, only used if message_id is provided
# Look for patterns like "reason 1234567890123456789" or "reason 1234567890123456789 15" # Look for patterns like "reason 1234567890123456789" or "reason 1234567890123456789 15"
if len(reason_words) >= 2: if len(reason_words) >= 2:
@@ -3025,6 +3027,14 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
# Update reason without the message ID and context range # Update reason without the message ID and context range
reason = " ".join(reason_words) reason = " ".join(reason_words)
# Only use context_range parameter if message_id is also provided
if parsed_message_id and message_id and context_range != 3:
# If message_id was provided as parameter and context_range was also set, use it
parsed_context_range = context_range
elif not parsed_message_id:
# If no message_id was found, reset context_range to default
parsed_context_range = 3
# Validate and limit context range # Validate and limit context range
if parsed_context_range < 1: if parsed_context_range < 1:
parsed_context_range = 1 parsed_context_range = 1
@@ -3810,8 +3820,8 @@ async def mute(ctx, user: discord.User, duration: str, reason: str = "No reason
- user: The user to mute - user: The user to mute
- duration: Duration (10m, 1h, 2d) - duration: Duration (10m, 1h, 2d)
- reason: Reason for the mute (can include message ID and context range) - reason: Reason for the mute (can include message ID and context range)
- message_id: Optional message ID to reference - message_id: Optional message ID to reference (required for context_range)
- context_range: Number of context messages to archive (1-25, default: 3) - context_range: Number of context messages to archive (only works with message_id)
Duration examples: Duration examples:
- 10m = 10 minutes - 10m = 10 minutes
@@ -3820,6 +3830,8 @@ async def mute(ctx, user: discord.User, duration: str, reason: str = "No reason
You can also specify message ID and context range in the reason: You can also specify message ID and context range in the reason:
"Bad language 1407754702564884622 15" (15 messages before/after) "Bad language 1407754702564884622 15" (15 messages before/after)
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
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
@@ -3845,7 +3857,7 @@ async def mute(ctx, user: discord.User, duration: str, reason: str = "No reason
# Parse message ID and context range from reason if they look valid # Parse message ID and context range from reason if they look valid
original_reason = reason original_reason = reason
message_data = None message_data = None
parsed_context_range = context_range parsed_context_range = 3 # Default context range, only used if message_id is provided
# Check if reason contains potential message ID and context range # Check if reason contains potential message ID and context range
reason_words = reason.split() reason_words = reason.split()
@@ -3867,6 +3879,14 @@ async def mute(ctx, user: discord.User, duration: str, reason: str = "No reason
message_id = potential_msg_id message_id = potential_msg_id
reason = " ".join(reason_words[:-1]) # Remove message ID from reason reason = " ".join(reason_words[:-1]) # Remove message ID from reason
# Only use context_range parameter if message_id is also provided
if message_id and context_range != 3:
# If message_id was provided and context_range was also set, use it
parsed_context_range = context_range
elif not message_id:
# If no message_id was found, reset context_range to default
parsed_context_range = 3
# Validate and limit context range # Validate and limit context range
if parsed_context_range < 1: if parsed_context_range < 1:
parsed_context_range = 1 parsed_context_range = 1