'"Pickling" a weakref

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)

Using the discord API, I have been trying to save the channel that will relay admin information across runs by saving the channel object to a file, but I am getting this error:

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


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source