#🔒 Python code doesent work for /quote cmd (dc bot)

17 messages · Page 1 of 1 (latest)

alpine forge
#

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"))
sleek tendonBOT
#

@alpine forge

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

frigid hazel
#

Note that a slash command won't be a reply to a message at the same time

jolly forum
#

!code

sleek tendonBOT
#
Formatting code on Discord

Here's how to format Python code on Discord:

```py
print('Hello world!')
```

These are backticks, not quotes. Check this out if you can't find the backtick key.

For long code samples, you can use our pastebin.

frigid hazel
#

You might want to use context menu

#

!d discord.app_commands.context_menu

sleek tendonBOT
#

@discord.app_commands.context_menu(*, name=..., nsfw=False, auto_locale_strings=True, extras=...)```
Creates an application command context menu from a regular function.

This function must have a signature of [`Interaction`](https://discordpy.readthedocs.io/en/stable/interactions/api.html#discord.Interaction) as its first parameter and taking either a [`Member`](https://discordpy.readthedocs.io/en/stable/api.html#discord.Member), [`User`](https://discordpy.readthedocs.io/en/stable/api.html#discord.User), or [`Message`](https://discordpy.readthedocs.io/en/stable/api.html#discord.Message), or a [`typing.Union`](https://docs.python.org/3/library/typing.html#typing.Union) of `Member` and `User` as its second parameter.

Examples...
#

Hey @alpine forge!

Please edit your message to use a code block

```py
print('Hello, world!')
```

This will result in the following:

print('Hello, world!')```
alpine forge
alpine forge
#
async def quote(interaction: discord.Interaction):
    ref = interaction.message.reference
    if ref is None:
        await interaction.response.defer(ephemeral=True)
        await interaction.followup.send(":x: 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(":x: 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"))```
frigid hazel
#

I would assume so

sleek tendonBOT
#
Python help channel closed for inactivity

This help channel has been closed. Feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.