首页 > 解决方案 > 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

有人可以帮我解决这个问题吗?

标签: pythondiscorddiscord.py

解决方案


content = proxies_formated.encode()

是如何将 str 转换为字节。

旁注:其拼写为“格式”,带有 2 个 t。


推荐阅读