modified: bot.py
This commit is contained in:
68
bot.py
68
bot.py
@@ -2927,19 +2927,11 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
|||||||
- reason: Reason for the warning
|
- reason: Reason for the warning
|
||||||
- message_id: Optional message ID to reference
|
- message_id: Optional message ID to reference
|
||||||
"""
|
"""
|
||||||
# Defer the response immediately to prevent timeout (only for slash commands)
|
# Check if it's a slash command and defer if needed
|
||||||
if hasattr(ctx, 'interaction') and ctx.interaction:
|
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
|
||||||
|
if is_slash_command:
|
||||||
await ctx.defer()
|
await ctx.defer()
|
||||||
|
|
||||||
# Helper function to send messages correctly based on command type
|
|
||||||
async def send_response(content=None, embed=None, ephemeral=False):
|
|
||||||
if hasattr(ctx, 'interaction') and ctx.interaction:
|
|
||||||
# Slash command - use followup
|
|
||||||
await ctx.followup.send(content=content, embed=embed, ephemeral=ephemeral)
|
|
||||||
else:
|
|
||||||
# Prefix command - use normal send
|
|
||||||
await ctx.send(content=content, embed=embed)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# message_data will be populated if message_id is provided
|
# message_data will be populated if message_id is provided
|
||||||
message_data = None
|
message_data = None
|
||||||
@@ -2950,7 +2942,10 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
|||||||
try:
|
try:
|
||||||
message_id_int = int(message_id)
|
message_id_int = int(message_id)
|
||||||
except ValueError:
|
except ValueError:
|
||||||
await send_response(content=f"❌ Invalid message ID: {message_id}")
|
if is_slash_command:
|
||||||
|
await ctx.followup.send(f"❌ Invalid message ID: {message_id}")
|
||||||
|
else:
|
||||||
|
await ctx.send(f"❌ Invalid message ID: {message_id}")
|
||||||
return
|
return
|
||||||
# Try to get message data from current channel first
|
# Try to get message data from current channel first
|
||||||
message_data = await get_message_data(ctx.channel, message_id_int)
|
message_data = await get_message_data(ctx.channel, message_id_int)
|
||||||
@@ -2975,7 +2970,10 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
|||||||
description="You need moderation permissions (Level 5 or higher) to use this command.",
|
description="You need moderation permissions (Level 5 or higher) to use this command.",
|
||||||
color=0xff0000
|
color=0xff0000
|
||||||
)
|
)
|
||||||
await send_response(embed=embed, ephemeral=True)
|
if is_slash_command:
|
||||||
|
await ctx.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await ctx.send(embed=embed)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Cannot warn yourself
|
# Cannot warn yourself
|
||||||
@@ -2985,7 +2983,10 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
|||||||
description="You cannot warn yourself!",
|
description="You cannot warn yourself!",
|
||||||
color=0xff0000
|
color=0xff0000
|
||||||
)
|
)
|
||||||
await send_response(embed=embed, ephemeral=True)
|
if is_slash_command:
|
||||||
|
await ctx.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await ctx.send(embed=embed)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Check if target has higher permissions
|
# Check if target has higher permissions
|
||||||
@@ -2997,7 +2998,10 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
|||||||
description="You cannot warn someone with equal or higher permissions than you.",
|
description="You cannot warn someone with equal or higher permissions than you.",
|
||||||
color=0xff0000
|
color=0xff0000
|
||||||
)
|
)
|
||||||
await send_response(embed=embed, ephemeral=True)
|
if is_slash_command:
|
||||||
|
await ctx.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await ctx.send(embed=embed)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Increase warn count
|
# Increase warn count
|
||||||
@@ -3102,7 +3106,10 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
|||||||
inline=False
|
inline=False
|
||||||
)
|
)
|
||||||
|
|
||||||
await send_response(embed=embed)
|
if is_slash_command:
|
||||||
|
await ctx.followup.send(embed=embed)
|
||||||
|
else:
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
# Log the warning action
|
# Log the warning action
|
||||||
log_additional_info = {
|
log_additional_info = {
|
||||||
@@ -3159,7 +3166,10 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
|||||||
description="An error occurred while processing the warning. Please try again.",
|
description="An error occurred while processing the warning. Please try again.",
|
||||||
color=0xff0000
|
color=0xff0000
|
||||||
)
|
)
|
||||||
await send_response(embed=embed)
|
if is_slash_command:
|
||||||
|
await ctx.followup.send(embed=embed)
|
||||||
|
else:
|
||||||
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@client.hybrid_command()
|
@client.hybrid_command()
|
||||||
async def mywarns(ctx):
|
async def mywarns(ctx):
|
||||||
@@ -3490,6 +3500,11 @@ async def modinfo(ctx, user: discord.User = None):
|
|||||||
@client.hybrid_command()
|
@client.hybrid_command()
|
||||||
async def viewwarn(ctx, warning_id: int):
|
async def viewwarn(ctx, warning_id: int):
|
||||||
"""View detailed information about a specific warning (Requires Permission Level 5 or higher)"""
|
"""View detailed information about a specific warning (Requires Permission Level 5 or higher)"""
|
||||||
|
# Check if it's a slash command and defer if needed
|
||||||
|
is_slash_command = hasattr(ctx, 'interaction') and ctx.interaction
|
||||||
|
if is_slash_command:
|
||||||
|
await ctx.defer()
|
||||||
|
|
||||||
try:
|
try:
|
||||||
# Load moderator data
|
# Load moderator data
|
||||||
mod_data = await load_user_data(ctx.author.id, ctx.guild.id)
|
mod_data = await load_user_data(ctx.author.id, ctx.guild.id)
|
||||||
@@ -3501,7 +3516,10 @@ async def viewwarn(ctx, warning_id: int):
|
|||||||
description="You need moderation permissions (Level 5 or higher) to use this command.",
|
description="You need moderation permissions (Level 5 or higher) to use this command.",
|
||||||
color=0xff0000
|
color=0xff0000
|
||||||
)
|
)
|
||||||
await ctx.send(embed=embed, ephemeral=True)
|
if is_slash_command:
|
||||||
|
await ctx.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await ctx.send(embed=embed)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get warning details from database
|
# Get warning details from database
|
||||||
@@ -3527,7 +3545,10 @@ async def viewwarn(ctx, warning_id: int):
|
|||||||
description=f"No warning with ID {warning_id} found in this server.",
|
description=f"No warning with ID {warning_id} found in this server.",
|
||||||
color=0xff0000
|
color=0xff0000
|
||||||
)
|
)
|
||||||
await ctx.send(embed=embed, ephemeral=True)
|
if is_slash_command:
|
||||||
|
await ctx.followup.send(embed=embed, ephemeral=True)
|
||||||
|
else:
|
||||||
|
await ctx.send(embed=embed)
|
||||||
return
|
return
|
||||||
|
|
||||||
# Parse result
|
# Parse result
|
||||||
@@ -3592,6 +3613,9 @@ async def viewwarn(ctx, warning_id: int):
|
|||||||
|
|
||||||
# Send image separately if it's the first attachment
|
# Send image separately if it's the first attachment
|
||||||
if i == 0:
|
if i == 0:
|
||||||
|
if is_slash_command:
|
||||||
|
await ctx.followup.send(f"📎 **Attachment from Warning {warning_id}:**", file=file)
|
||||||
|
else:
|
||||||
await ctx.send(f"📎 **Attachment from Warning {warning_id}:**", file=file)
|
await ctx.send(f"📎 **Attachment from Warning {warning_id}:**", file=file)
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
logger.warning(f"Could not display attachment: {e}")
|
logger.warning(f"Could not display attachment: {e}")
|
||||||
@@ -3606,6 +3630,9 @@ async def viewwarn(ctx, warning_id: int):
|
|||||||
embed.set_thumbnail(url=warned_user.display_avatar.url)
|
embed.set_thumbnail(url=warned_user.display_avatar.url)
|
||||||
embed.set_footer(text=f"Warning ID: {warning_id} | Guild: {ctx.guild.name}")
|
embed.set_footer(text=f"Warning ID: {warning_id} | Guild: {ctx.guild.name}")
|
||||||
|
|
||||||
|
if is_slash_command:
|
||||||
|
await ctx.followup.send(embed=embed)
|
||||||
|
else:
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
finally:
|
finally:
|
||||||
@@ -3621,6 +3648,9 @@ async def viewwarn(ctx, warning_id: int):
|
|||||||
description="An error occurred while retrieving warning details. Please try again.",
|
description="An error occurred while retrieving warning details. Please try again.",
|
||||||
color=0xff0000
|
color=0xff0000
|
||||||
)
|
)
|
||||||
|
if is_slash_command:
|
||||||
|
await ctx.followup.send(embed=embed)
|
||||||
|
else:
|
||||||
await ctx.send(embed=embed)
|
await ctx.send(embed=embed)
|
||||||
|
|
||||||
@client.hybrid_command()
|
@client.hybrid_command()
|
||||||
|
|||||||
Reference in New Issue
Block a user