在不和谐的机器人中从网站上传图像
Uploading images from website in a discord bot
await ctx.send(file=discord.File(r'www.abc.com/wal1.jpg')
它不是这样工作的
在 discord 上,指向文件的链接会自动转换为该文件,因此您应该避开:
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"))
await ctx.send(file=discord.File(r'www.abc.com/wal1.jpg')
它不是这样工作的
在 discord 上,指向文件的链接会自动转换为该文件,因此您应该避开:
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"))