modified: bot.py

This commit is contained in:
SimolZimol
2025-08-20 19:49:32 +02:00
parent f03421fddd
commit 7ce4324304

48
bot.py
View File

@@ -2933,17 +2933,17 @@ async def warn(ctx, user: discord.User, reason: str = "No reason provided", mess
await ctx.defer() await ctx.defer()
# Helper function for sending responses # Helper function for sending responses
async def send_response(content=None, embed=None, ephemeral=False): async def send_response(content=None, embed=None, ephemeral=False, file=None):
try: try:
if is_slash_command: if is_slash_command:
await ctx.followup.send(content=content, embed=embed, ephemeral=ephemeral) await ctx.followup.send(content=content, embed=embed, ephemeral=ephemeral, file=file)
else: else:
await ctx.send(content=content, embed=embed) await ctx.send(content=content, embed=embed, file=file)
except Exception as e: except Exception as e:
logger.error(f"Error sending response: {e}") logger.error(f"Error sending response: {e}")
# Fallback to regular send if followup fails # Fallback to regular send if followup fails
try: try:
await ctx.send(content=content, embed=embed) await ctx.send(content=content, embed=embed, file=file)
except: except:
pass pass
@@ -3506,6 +3506,21 @@ async def viewwarn(ctx, warning_id: int):
if is_slash_command: if is_slash_command:
await ctx.defer() await ctx.defer()
# Helper function for sending responses
async def send_response(content=None, embed=None, ephemeral=False, file=None):
try:
if is_slash_command:
await ctx.followup.send(content=content, embed=embed, ephemeral=ephemeral, file=file)
else:
await ctx.send(content=content, embed=embed, file=file)
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, file=file)
except:
pass
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)
@@ -3517,10 +3532,7 @@ 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
) )
if is_slash_command: await send_response(embed=embed, ephemeral=True)
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
@@ -3546,10 +3558,7 @@ 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
) )
if is_slash_command: await send_response(embed=embed, ephemeral=True)
await ctx.followup.send(embed=embed, ephemeral=True)
else:
await ctx.send(embed=embed)
return return
# Parse result # Parse result
@@ -3614,10 +3623,7 @@ 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 send_response(content=f"📎 **Attachment from Warning {warning_id}:**", file=file)
await ctx.followup.send(f"📎 **Attachment from Warning {warning_id}:**", file=file)
else:
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}")
@@ -3631,10 +3637,7 @@ 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 send_response(embed=embed)
await ctx.followup.send(embed=embed)
else:
await ctx.send(embed=embed)
finally: finally:
if cursor: if cursor:
@@ -3649,10 +3652,7 @@ 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 send_response(embed=embed)
await ctx.followup.send(embed=embed)
else:
await ctx.send(embed=embed)
@client.hybrid_command() @client.hybrid_command()
async def mute(ctx, user: discord.User, duration: str, *, reason: str = "No reason provided"): async def mute(ctx, user: discord.User, duration: str, *, reason: str = "No reason provided"):