繁体   English   中英

可以在 python 中使用 discord api 中的相对路径吗?

[英]It is possible to use relative path in discord api in python?

早上好,感谢 Discord ZDB974238714CA8DE634A7CE1D083A,我在 python 中开发了一个 discord 机器人。 所以我想用这个机器人上传一张图片,在代码中我想使用一个相对路径,以简化它何时上传到服务器上。 但它没有用。 我不得不使用不是很有用的绝对路径。 请问你有什么解决办法。 谢谢你。

@bot.command()
async def command(ctx):
    await ctx.send(file=discord.File('photos/picture.jpg')) 

这里是终端:

discord.ext.commands.errors.CommandInvokeError: Command raised an exception: FileNotFoundError: [Errno 2] No such file or directory: '/photos/picture.jpg'

文档

file = discord.File("path/to/my/image.png", filename="image.png")
embed = discord.Embed()
embed.set_image(url="attachment://image.png")
await channel.send(file=file, embed=embed)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM