如何使用discord.py发送图像

时间:2020-03-29 10:51:36

标签: python 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)

我正在尝试使不和谐的bot在服务器中发送.ss时发送屏幕截图,而我正在使用python 3.8.2,有人知道一种方法,因为我在任何地方都找不到方法?

1 个答案:

答案 0 :(得分:0)

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