[英](discord.py) How to send content of a text file as a message
I want my bot to send ascii art.我希望我的机器人发送 ascii 艺术。 The art is contained in a text file because it's more organized, but when i try to make the bot send it it just sends the file download.
艺术包含在文本文件中,因为它更有条理,但是当我尝试让机器人发送它时,它只会发送文件下载。 I am currently using
await ctx.send(file=discord.File('file path'))
.我目前正在使用
await ctx.send(file=discord.File('file path'))
。 How do i convert the contents of the file to a string that can be sent as a message?如何将文件的内容转换为可以作为消息发送的字符串?
You need to open the txt file read its content and send it您需要打开txt文件读取其内容并发送
with open("filename.txt") as f:
content = "\n".join(f.readlines())
await ctx.send(content)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.