在discord bot中从网站上载图像

2024-10-01 07:47:57 发布

您现在位置:Python中文网/ 问答频道 /正文

await ctx.send(file=discord.File(r'www.abc.com/wal1.jpg') 这样不行


Tags: comsendwwwawaitfilejpgctxabc
1条回答
网友
1楼 · 发布于 2024-10-01 07:47:57

在不一致情况下,指向文件的链接将自动转换为该文件,因此您应该避免:

await ctx.send("www.abc.com/wal1.jpg")

如果您确实想发送文件,可以下载它,然后使用discord.File()方法发送。大概是这样的:

response = requests.get("www.abc.com/wal1.jpg")
with open(f"img.jpg", "wb") as file:
    file.write(response.content)
await ctx.send(file=discord.File("img.jpg"))

相关问题 更多 >