modified: bot.py
This commit is contained in:
51
bot.py
51
bot.py
@@ -2932,6 +2932,21 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
||||
if is_slash_command:
|
||||
await ctx.defer()
|
||||
|
||||
# Helper function for sending responses
|
||||
async def send_response(content=None, embed=None, ephemeral=False):
|
||||
try:
|
||||
if is_slash_command:
|
||||
await ctx.followup.send(content=content, embed=embed, ephemeral=ephemeral)
|
||||
else:
|
||||
await ctx.send(content=content, embed=embed)
|
||||
except Exception as e:
|
||||
logger.error(f"Error sending response: {e}")
|
||||
# Fallback to regular send if followup fails
|
||||
try:
|
||||
await ctx.send(content=content, embed=embed)
|
||||
except:
|
||||
pass
|
||||
|
||||
try:
|
||||
# message_data will be populated if message_id is provided
|
||||
message_data = None
|
||||
@@ -2942,17 +2957,18 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
||||
try:
|
||||
message_id_int = int(message_id)
|
||||
except ValueError:
|
||||
if is_slash_command:
|
||||
await ctx.followup.send(f"❌ Invalid message ID: {message_id}")
|
||||
else:
|
||||
await ctx.send(f"❌ Invalid message ID: {message_id}")
|
||||
await send_response(content=f"❌ Invalid message ID: {message_id}")
|
||||
return
|
||||
# Try to get message data from current channel first
|
||||
message_data = await get_message_data(ctx.channel, message_id_int)
|
||||
|
||||
# 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:
|
||||
# Limit search to avoid spam - only check first 10 channels
|
||||
channels_to_check = ctx.guild.text_channels[:10]
|
||||
for channel in channels_to_check:
|
||||
if channel.id == ctx.channel.id:
|
||||
continue # Skip current channel, already checked
|
||||
try:
|
||||
message_data = await get_message_data(channel, message_id_int)
|
||||
if message_data is not None:
|
||||
@@ -2970,10 +2986,7 @@ 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.",
|
||||
color=0xff0000
|
||||
)
|
||||
if is_slash_command:
|
||||
await ctx.followup.send(embed=embed, ephemeral=True)
|
||||
else:
|
||||
await ctx.send(embed=embed)
|
||||
await send_response(embed=embed, ephemeral=True)
|
||||
return
|
||||
|
||||
# Cannot warn yourself
|
||||
@@ -2983,10 +2996,7 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
||||
description="You cannot warn yourself!",
|
||||
color=0xff0000
|
||||
)
|
||||
if is_slash_command:
|
||||
await ctx.followup.send(embed=embed, ephemeral=True)
|
||||
else:
|
||||
await ctx.send(embed=embed)
|
||||
await send_response(embed=embed, ephemeral=True)
|
||||
return
|
||||
|
||||
# Check if target has higher permissions
|
||||
@@ -2998,10 +3008,7 @@ 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.",
|
||||
color=0xff0000
|
||||
)
|
||||
if is_slash_command:
|
||||
await ctx.followup.send(embed=embed, ephemeral=True)
|
||||
else:
|
||||
await ctx.send(embed=embed)
|
||||
await send_response(embed=embed, ephemeral=True)
|
||||
return
|
||||
|
||||
# Increase warn count
|
||||
@@ -3106,10 +3113,7 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
||||
inline=False
|
||||
)
|
||||
|
||||
if is_slash_command:
|
||||
await ctx.followup.send(embed=embed)
|
||||
else:
|
||||
await ctx.send(embed=embed)
|
||||
await send_response(embed=embed)
|
||||
|
||||
# Log the warning action
|
||||
log_additional_info = {
|
||||
@@ -3166,10 +3170,7 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
|
||||
description="An error occurred while processing the warning. Please try again.",
|
||||
color=0xff0000
|
||||
)
|
||||
if is_slash_command:
|
||||
await ctx.followup.send(embed=embed)
|
||||
else:
|
||||
await ctx.send(embed=embed)
|
||||
await send_response(embed=embed)
|
||||
|
||||
@client.hybrid_command()
|
||||
async def mywarns(ctx):
|
||||
|
||||
Reference in New Issue
Block a user