Python 3.x discord.py-发送虚拟PDF文件
是否有办法将虚拟PDF文件上载到Discord(我不希望在我的计算机上创建文件)。我已经知道我可以通过以下方式发送虚拟Python 3.x discord.py-发送虚拟PDF文件,python-3.x,discord,discord.py,discord.py-rewrite,Python 3.x,Discord,Discord.py,Discord.py Rewrite,是否有办法将虚拟PDF文件上载到Discord(我不希望在我的计算机上创建文件)。我已经知道我可以通过以下方式发送虚拟txt文件: 导入不一致,异步 从discord.ext导入命令 从io导入StringIO bot=commands.bot() @bot.command() 异步def发送(ctx,*,字符串): 等待ctx.send(file=discord.file( fp=StringIO(“这是一项测试”), filename=“Test.txt” ) 但这不适用于PDF文件。我尝
txt
文件:
导入不一致,异步
从discord.ext导入命令
从io导入StringIO
bot=commands.bot()
@bot.command()
异步def发送(ctx,*,字符串):
等待ctx.send(file=discord.file(
fp=StringIO(“这是一项测试”),
filename=“Test.txt”
)
但这不适用于PDF文件。我尝试改用,但没有结果。有人知道如何解决此问题吗?下面是一个使用的示例:
导入不一致
从discord.ext导入命令
从io导入字节io
从fpdf导入fpdf
bot=commands.bot(“!”)
@bot.command()
异步定义pdf(ctx,*,文本):
pdf=FPDF()
pdf.add_page()
pdf.set_字体('Arial','B',16)
pdf.cell(40,10,文本)
bstring=pdf.output(dest='S').encode('latin-1'))
等待ctx.send(file=discord.file(BytesIO(bstring),filename='pdf.pdf'))
bot.run(“令牌”)
下面是一个使用以下内容的示例:
导入不一致
从discord.ext导入命令
从io导入字节io
从fpdf导入fpdf
bot=commands.bot(“!”)
@bot.command()
异步定义pdf(ctx,*,文本):
pdf=FPDF()
pdf.add_page()
pdf.set_字体('Arial','B',16)
pdf.cell(40,10,文本)
bstring=pdf.output(dest='S').encode('latin-1'))
等待ctx.send(file=discord.file(BytesIO(bstring),filename='pdf.pdf'))
bot.run(“令牌”)