python-3.x - Discord.py 重写 || 发送文件
问题描述
我需要将chat.log 文件附加到消息中,但出现异常
Ignoring exception in on_message
Traceback (most recent call last):
File "C:\Users\vlad0\AppData\Roaming\Python\Python36\site-packages\discord\client.py", line 227, in _run_event
await coro(*args, **kwargs)
File "c:\Users\vlad0\Desktop\bot\bot.py", line 660, in on_message
await channel.send('***Log for ticket #{id}***'.format(id = text),file = f )
File "C:\Users\vlad0\AppData\Roaming\Python\Python36\site-packages\discord\abc.py", line 752, in send
raise InvalidArgument('file parameter must be File')
discord.errors.InvalidArgument: file parameter must be File
我的代码:
with open(file[0]+'/chat.log','r', encoding='UTF-8') as f:
await channel.send('***Log for ticket #{id}***'.format(id = text),file = f.read() )
当我使用“rb”阅读时会发生同样的事情,如果您只指定文件的路径,也会发生同样的事情 如何将文件附加到消息?
解决方案
to 的参数file
必须是一个discord.File
对象:
from discord import File
await channel.send('***Log for ticket #{id}***'.format(id = text), file=File(file[0]+'/chat.log'))
推荐阅读
- tensorflow - TensorFlow:如何使用 TensorHub 模块导出估算器?
- amazon-web-services - 有没有办法从 URL 列表中将 50000 个图像文件上传到 Amazon S3 Bucket
- python - python 3将值从一个sqlite数据库中的分隔表中存储到列表中
- python - 如何打印 ACTUAL SQLAlchemy 查询以进行故障排除:SQLAlchemy 过滤器语句将过滤器条件替换为 %(column_name_1)s
- html - HTML 输入文本上的日历
- excel - 如何交换多个单元格?
- javascript - 如何在 Vue.js 中使用 JSZip 下载 .zip 文件夹中的多个图像文件
- linux - OCI 运行时执行失败 - Container_linux.go:348
- java - Wildfly 13 具有错误版本的 Maven 依赖项
- kubernetes - 如何使用 watch api 避免丢失历史删除事件