user12393095
user12393095

Reputation:

How to send a image with discord.py

@client.command(past_context = True)
async def ss(ctx):
    try:
        os.remove("ss.png")
    except:
        pass
    pyautogui.screenshot("ss.png")
    now = datetime.now()
    current_time = now.strftime("%H:%M:%S")
    file = File(filename="ss.png")
    await ctx.send(file=file)

I'm trying to make a discord bot that send a screenshot when .ss is sent in the server i'm useing python 3.8.2 does anyone know a way as i can't find a way anywhere?

Upvotes: 0

Views: 7683

Answers (1)

david
david

Reputation: 1501

with open(my_filename, "rb") as fh:
    f = discord.File(fh, filename=my_filename)
await ctx.send(file=f)

Upvotes: 3

Related Questions