Skip to content

Commit

Permalink
trim the response due to discord embed limitations
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanSmudja committed Dec 20, 2023
1 parent 83d624d commit 6c4d573
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
2 changes: 1 addition & 1 deletion 8ball_responses.txt
Original file line number Diff line number Diff line change
Expand Up @@ -26,4 +26,4 @@ Bra fråga, svårt att säga
Jag vet inte, försök igen
Kan inte svara nu
Fråga mig senare, jag är upptagen
Det är bättre du inte vet det nu"
Det är bättre du inte vet det nu
10 changes: 6 additions & 4 deletions bot.py
Original file line number Diff line number Diff line change
Expand Up @@ -139,10 +139,10 @@ async def balle(interraction: discord.Interaction):


@bot.tree.command(name="chatgpt")
async def gpt(interraction: discord.Interaction, *, gpt_input: str):
async def gpt(interraction: discord.Interaction, *, fråga: str):
"""Ställ GPT-3.5 en fråga"""
await interraction.response.defer()
gpt_response = await chat_with_gpt(gpt_input)
gpt_response = await chat_with_gpt(fråga)

embed = discord.Embed(
description=f"{interraction.user.mention} frågade GPT-3.5:",
Expand All @@ -154,8 +154,10 @@ async def gpt(interraction: discord.Interaction, *, gpt_input: str):
icon_url="https://github.com/lilstiffy/StiffyBot/blob/master/assets/chatgpt.png?raw=true"
)

embed.add_field(name="", value=gpt_input, inline=False)
embed.add_field(name="Svar", value=gpt_response, inline=False)
trimmed_response = gpt_response[:1020] + "..." if len(gpt_response) > 1020 else gpt_response

embed.add_field(name="", value=fråga, inline=False)
embed.add_field(name="Svar", value=trimmed_response, inline=False)

await interraction.followup.send(embed=embed)

Expand Down

0 comments on commit 6c4d573

Please sign in to comment.