簡體   English   中英

(discord.py) 如何將文本文件的內容作為消息發送

[英](discord.py) How to send content of a text file as a message

我希望我的機器人發送 ascii 藝術。 藝術包含在文本文件中,因為它更有條理,但是當我嘗試讓機器人發送它時,它只會發送文件下載。 我目前正在使用await ctx.send(file=discord.File('file path')) 如何將文件的內容轉換為可以作為消息發送的字符串?

您需要打開txt文件讀取其內容並發送

with open("filename.txt") as f:
    content = "\n".join(f.readlines())

await ctx.send(content)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM