A part of my code doesent work, everytime I execute the cmd on discord the bot says: "This interaction doesent react"
Here my code:
@bot.tree.command(name="quote", description="Make a quote image from a replied message")
async def quote(interaction: discord.Interaction):
ref = interaction.message.reference
if ref is None:
await interaction.response.defer(ephemeral=True)
await interaction.followup.send("❌ Please use this command as a reply to a message!")
return
try:
channel = interaction.channel
msg = await channel.fetch_message(ref.message_id)
except:
await interaction.response.defer(ephemeral=True)
await interaction.followup.send("❌ Could not fetch the replied message.")
return
# Bild erstellen
await interaction.response.defer()
# Basisbildgröße
width, height = 800, 250
background_color = (54, 57, 63) # Discord-dark-gray
# Erstelle leeres Bild
img = Image.new("RGBA", (width, height), background_color)
draw = ImageDraw.Draw(img)
# Schrift laden (achte darauf, dass der Pfad zur Font stimmt)
try:
font_bold = ImageFont.truetype("arialbd.ttf", 28) # fetter Font
font_regular = ImageFont.truetype("arial.ttf", 22)
except:
# Fallback auf Default-Font
font_bold = ImageFont.load_default()
font_regular = ImageFont.load_default()
# Username zeichnen
username = msg.author.display_name
draw.text((150, 20), username, font=font_bold, fill=(255, 255, 255))
# Nachricht (dick geschrieben)
text = msg.content
# Um Text umbrechen, max. Breite beachten
def draw_text_wrapped(draw, text, position, font, max_width, fill):
lines = []
words = text.split()
line = ""
for word in words:
test_line = line + word + " "
w, h = draw.textsize(test_line, font=font)
if w <= max_width:
line = test_line
else:
lines.append(line)
line = word + " "
lines.append(line)
y = position[1]
for line in lines:
draw.text((position[0], y), line.strip(), font=font, fill=fill)
y += font.getsize(line)[1] + 5
return y
draw_text_wrapped(draw, text, (150, 60), font_bold, 620, (255, 255, 255))
# Avatar holen & zeichnen (kreisförmig)
avatar_url = msg.author.display_avatar.url
async with aiohttp.ClientSession() as session:
async with session.get(avatar_url) as resp:
if resp.status != 200:
avatar_img = None
else:
data = await resp.read()
avatar_img = Image.open(BytesIO(data)).convert("RGBA")
avatar_img = avatar_img.resize((120, 120))
# Kreis-Maske erstellen
mask = Image.new("L", (120, 120), 0)
mask_draw = ImageDraw.Draw(mask)
mask_draw.ellipse((0, 0, 120, 120), fill=255)
# Avatar mit Maske einfügen
img.paste(avatar_img, (10, 20), mask)
# Bild speichern in BytesIO
with BytesIO() as image_binary:
img.save(image_binary, "PNG")
image_binary.seek(0)
await interaction.followup.send(file=discord.File(fp=image_binary, filename="quote.png"))