How can I properly send a text file with my Discord bot?

Viewed 139

I am currently developing a bot and trying to read out some content from a fetched message.

This part works fine. I then store the content in a text file, line breaks etc., included; these do not come from my bot.

Printing the content and looking at the text file, I have a format like this:

*This is just a test-embed you read out*

1) Test 1
2) Test 2

Test done...

However, giving this out as a text file with my bot does not work. Only the following format does not run into an error:

*This is just a test-embed you read out*1) Test 12) Test 2Test done...

I do not really want this. Speaking about the error, it is the following:

await interaction.channel.send(file=discord.File(fp=f))
[...]
ClientOSError: [WinError 64] The specified network name is no longer available

I use the following to send out the file:

with open(f"{interaction.guild.id}.txt", "r") as f:
    await interaction.channel.send(file=discord.File(fp=f))

and the following to store the content in a file:

with open(f"{interaction.guild.id}.txt", "w+") as file:
    file.write(fetched_description)
0 Answers
Related