#๐Ÿ”’ Discord py making slash command send image

7 messages ยท Page 1 of 1 (latest)

limpid nacelle
#

This is my code that gives and image of a random quote (used with Pillow)

import discord
from discord.ext import commands, tasks
import random
from itertools import cycle
import os
import asyncio
import json
import httpx
import requests
from PIL import Image, ImageDraw, ImageFont
import textwrap



def make_quote():
    y = 50
    img_number = random.randint(1, 4)
    img = Image.open(f"Quote things/Backgrounds/{img_number}.png")
    with open("Quote things/quotes.txt") as file:
        selected = file.readlines()
        single_line = random.choice(selected)
        quote, author = single_line.split(" ~")
        wrapped = textwrap.TextWrapper(width=29)
        word_list = wrapped.wrap(text=quote)

    quoteFont = ImageFont.truetype("Quote things/Font/Poppins-Bold.ttf", 45)
    authorFont = ImageFont.truetype("Quote things/Font/Poppins-BoldItalic.ttf", 45)
    quote_draw = ImageDraw.Draw(img)
    author_draw = ImageDraw.Draw(img)

    for i in word_list:
        quote_draw.text((25, y), f"{i}", font=quoteFont, fill=(255, 255, 255), stroke_width=2, stroke_fill=(0, 0, 0))
        y += 50

    author_draw.text((25, 700), f"{author}", font=authorFont, fill=(54, 53, 50), stroke_width=2,
                     stroke_fill=(255, 255, 255))

    img.save("Quote things/Images/Quote.png")

@client.command(name="quoteimage", description="quote image")
async def quoteimage(ctx):
    make_quote()
    await ctx.send(file=discord.File("Quote things/Images/Quote.png"))

It works and sends an image when i do !quoteimage.

How would i make it work with /quoteimage

tired leafBOT
#

@limpid nacelle

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.

limpid nacelle
#

!c;pse

tired leafBOT
#
Did you mean:

!close

limpid nacelle
#

!close

tired leafBOT
#
Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, 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.