Discord.py发送空白的.txt文件

时间:2020-07-19 11:50:43

标签: python-3.x discord.py

我正在尝试将大量数据输出到txt文件并通过命令不和谐发送,其余命令工作正常,没有错误,但无论出于何种原因,发送的文本文件始终即使其中应该有大量数据也为空白。这是本节的原始代码:

with open("#PATH" , "w+") as F:
    F.write(f"name : {name}\n")
    F.write(f"xp history : {str(xp_history)}\n")
    F.write(f"date History : {str(date_history)}\n")
    await context.send(file = discord.File(F))

我后来将其更改为:

with open("#PATH" , "w+") as F:
    F.write(f"name : {name}\n")
    F.write(f"xp history : {str(xp_history)}\n")
    F.write(f"date History : {str(date_history)}\n")
with open("#PATH" , "w+") as F:
    await context.send(file = discord.File(F))

因为我认为它可能正在发送空白文档,因为它从未保存数据,但没有更改

edit:根据要求添加了其余的写入, 名称:字符串--- xp_history:数字列表--- date_history:字符串列表---

1 个答案:

答案 0 :(得分:0)

您在discord文件中传递了错误的数据。无需打开它,即使以“写入”模式打开文件,也可以直接在以下代码中输入路径。

await ctx.send(file = discord.File("#PATH including extension"))

路径从您的当前目录开始。 /