python - TypeError:无法腌制 _asyncio.Future 对象
问题描述
在我的 discord.py 机器人中修改后,我正在尝试使用 pickle 将列表保存到文件中。但是当机器人试图腌制一个列表并保存它时,我得到一个错误。已经尝试updateChannels()
使用相同的错误进行异步
Ignoring exception in on_message
Traceback (most recent call last):
File "/home/popek/.local/lib/python3.7/site-packages/discord/client.py", line 312, in _run_event
await coro(*args, **kwargs)
File "bot.py", line 177, in on_message
updateChannels()
File "bot.py", line 151, in updateChannels
pickle.dump(channels, f)
TypeError: can't pickle _asyncio.Future objects
import discord
import asyncio
import pickle
channels = []
try:
with open('channels.txt', encoding='utf-8') as f:
channels = pickle.load(f)
except TypeError:
pass
client = discord.Client()
def updateChannels():
global channels
with open('channels.txt', 'w', encoding='utf-8') as f:
pickle.dump(channels, f)
@client.event
async def on_message(message):
global channels
if message.content == ".enable":
if message.channel in channels:
await message.channel.send("Auto-messages already enabled on this channel")
else:
channels.append(message.channel)
updateChannels()
await message.channel.send("Enabled auto-messages on this channel")
# same for disabling
client.run("[TOKEN]")
解决方案
推荐阅读
- javascript - 如何在Javascript中检查条件是否为5秒
- linux - 使用标准外壳构建自定义应用程序特定外壳
- httprequest - HttpGet 设置 Accept 头后返回 406 错误
- python - 从字符串中省略 datetime.date
- javascript - 如何在 Cordorva inAppBrowser 中检测子浏览器自关闭事件而不是所有关闭操作
- java - CardStack 水平浏览器
- sqlite - ““,”附近的 SQLite 错误:语法错误
- java - 如何查找 if 或 else 代码已执行的次数?
- php - Wordpress Cron 不会触发 wp_mail() 但 php mail() 功能
- webhooks - 我可以使用 GIT 中的 WebHooks 将文件从我的 Master-Repo 分支复制到我的共享位置吗