python - TypeError:在Python中使用不和谐机器人发送数据时没有字符串参数的编码
问题描述
我正在尝试制作一个不和谐的机器人,它可以发送一个包含文本的 txt 文件。我已经尝试使用带有 BytesIO 类的 io moduke 来做到这一点。在以下代码中,您可以看到我已经尝试过的内容。
proxies_formated = 'Whats up'
content = bytes(str.encode, proxies_formated)
await message.author.send(file=discord.File(BytesIO(content), f"{message.author.id}.txt"))
但我收到以下错误:
content = bytes(str.encode, proxies_formated)
TypeError: encoding without a string argument
有人可以帮我解决这个问题吗?
解决方案
content = proxies_formated.encode()
是如何将 str 转换为字节。
旁注:其拼写为“格式”,带有 2 个 t。
推荐阅读
- javascript - 反应字符串过滤器方法返回空数组与.includes()条件
- php - PayPal WebHooks - Paypal-cert-url
- ssis - SQL Server Integration Services - 如何在 .dtsConfig 文件中获取当前日期并使用它生成文件名
- node.js - NodeJS / NPM / node-gyc / make - 有些东西不工作,无法安装 npm 模块 mdns
- python - OSError: Access Violation Writing with ctypes in python and CreateFileA in c++
- python - 更改链表中节点的数据不会更改引用同一内存地址的另一个变量的数据
- node.js - 让 node-oracledb 与强化的 macOS 应用程序一起工作时出错
- html - 如何将下拉箭头粘贴在一个地方
- python - python lambda函数的参数如何在循环中处理?
- python - 重定向 scikit-learn 打印的进度消息