Reputation: 3602
I was doing some research on Discord's capabilities today, and then I noticed that the "upload as file" option is given when a message is more than 2000 characters long.
The number plays a role here, but my statement can also be wrong, the fact is that some things are posted only as a link and or then not sent at all if I raise >2000
.
Here now the problem:
I am requesting data from Genius for a lyrics command. I already have some kind of override built in for when len(data["lyrics"])
is greater than 2000
"characters", that should be Discord's limit after all, otherwise the bot wouldn't be able to process the embed I am trying to send.
How can I manage that lyrics >2000
are sent as a file?
Relevant code:
if len(data["lyrics"]) > 2000:
return await ctx.send(f"<{data['links']['genius']}>"))
discord.File
with the corresponding piece of code above, does not work. (Something like file=discord.File(data)
was tried too!)ctx.file.send
does not work in this case eitherThe following posts were viewed:
What I want my bot to do if data["lyrics"] > 2000
:
Upvotes: 2
Views: 5826
Reputation: 15728
You can save the text into a io.StringIO
buffer and pass that into the discord.File
constructor:
from io import StringIO
text = data["lyrics"]
if len(text) > 2000:
buffer = StringIO(text)
f = discord.File(buffer, filename="lyrics.txt")
await ctx.send(file=f)
Upvotes: 4