1

I am working on a discord bot with nextcord, and want to save a discord user object on command. I have this code:

@commands.command()
     async def record(self, item):
     pickle.dump(item, open("filepath.txt", "wb"))

In discord that would be run like this:

.record @Username#0000

It is supposed to pickle the user object (@Username#0000) to filepath.txt, but instead it throws this error:

TypeError: cannot pickle 'TaskStepMethWrapper' object

Is there any other way to store and load objects that would be able to store and load 'TaskStepMethWrapper' object?

  • One option is always to pickle the member variables of the object. That also makes the pickling resilient to changes to the source code of the class – AJ Biffl Jan 05 '22 at 13:16
  • I also need to reconstruct the object, so that would not work. – Blackhole927 Jan 05 '22 at 13:21
  • Maybe this could help you https://stackoverflow.com/questions/30699391/python-how-can-i-make-this-un-pickleable-object-pickleable – Paul Kocian Jan 05 '22 at 13:22
  • What exactly are you passing to `record`? (What appears to be) a method wrapper doesn't seem like something you need to save and restulore. – chepner Jan 05 '22 at 13:23
  • I am passing a Nextcord User Object to record – Blackhole927 Jan 05 '22 at 13:31
  • I was assuming you had written the class yourself, and would be able to add the code to reconstruct objects in the constructor, or similar. Depending on how the objects are created, you still might be able to reconstruct objects by writing your own function. – AJ Biffl Jan 05 '22 at 13:40
  • I attempted using this post: [link] (https://stackoverflow.com/questions/30699391/python-how-can-i-make-this-un-pickleable-object-pickleable) And I couldn't get it to work for my purposes. Is there any other way? – Blackhole927 Jan 05 '22 at 15:05

0 Answers0