Add error handling for response sending in ask command

This commit is contained in:
Joakim Hellsén 2025-09-22 01:35:20 +02:00
commit 88503bc506

View file

@ -187,7 +187,14 @@ async def ask(interaction: discord.Interaction, text: str) -> None:
discord_file = discord.File(io.BytesIO(file_content), filename="response.txt") discord_file = discord.File(io.BytesIO(file_content), filename="response.txt")
await interaction.followup.send(f"{text}", file=discord_file) await interaction.followup.send(f"{text}", file=discord_file)
await interaction.followup.send(response) try:
await interaction.followup.send(response)
except discord.HTTPException as e:
e.add_note(f"Response length: {len(response)} characters.")
e.add_note(f"User input length: {len(text)} characters.")
logger.exception("Failed to send message to channel %s", interaction.channel)
await interaction.followup.send(f"Failed to send message: {e}")
def truncate_user_input(text: str) -> str: def truncate_user_input(text: str) -> str: