TypeError: невозможно выбрать _asyncio.Future объекты - PullRequest
0 голосов
/ 30 марта 2020

Я пытаюсь сохранить список в файл, используя pickle после того, как он был изменен в моем боте discord.py. Но когда бот пытается выбрать список и сохранить его, я получаю сообщение об ошибке. уже пытался сделать updateChannels() asyn c с такой же ошибкой

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]")

...