代码之家  ›  专栏  ›  技术社区  ›  zeke

“腌制”一个软面包

  •  0
  • zeke  · 技术社区  · 2 年前
    import os
    import discord
    import pickle
    
    if message.content.startswith("~setAdminChannel"):
        file = 'C:/Users/Zekeb/PycharmProjects/pythonProject4/venv/botInformation.txt'
    
        with open(file, 'w') as file:
            pickle.dump(message.channel, file)
    

    使用discord API,我一直试图通过将通道对象保存到文件来保存通道,该通道将在运行期间传递管理信息,但我遇到了以下错误:

    Ignoring exception in on_message
    Traceback (most recent call last):
      File "C:\Users\Zekeb\PycharmProjects\pythonProject4\venv\lib\site-packages\discord\client.py", line 343, in _run_event
        await coro(*args, **kwargs)
      File "C:\Users\Zekeb\PycharmProjects\pythonProject4\main.py", line 350, in on_message
        pickle.dump(message.channel, file)
    TypeError: cannot pickle 'weakref' object
    
    0 回复  |  直到 2 年前