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

标签: pythonasynchronouspython-asynciofuturediscord.py

解决方案


推荐阅读