1
votes

When trying to save my list of reactionrole objects with pickle it gives me the error Command raised an exception: TypeError: cannot pickle 'TaskStepMethWrapper' object. I have not tried anything because I'm not sure what TaskStepMethWrapper is. Here's my code:

@client.command()
async def reactionadd(ctx):
#  await ctx.send('Please give me the ID of the message you want to have a reactionrole on.')
#  msgid_var = await client.wait_for('message')
  await ctx.send('Please react with the emoji you want the reactionrole to use.')
  emoji_var = await client.wait_for('reaction_add')
#  await ctx.send('Please give me the ID of the role you want the reactionrole to give.')   
#  roleid_var = await client.wait_for('message')
  if not os.path.isfile('reactionrole.obj'):
    rrf = open('reactionrole.obj', 'xb')
    rrf.close()
  rrf = open('reactionrole.obj', 'rb+')
  if os.stat('reactionrole.obj').st_size == 0:
    rrobj = []
  else:
    rrobj = pickle.load(rrf)
  emoji_var = emoji_var[0]
  rrobj.append(reactionrole(749316751212150965, emoji_var, 749317419255857232))
  pickle.dump(rrobj, rrf)
  rrf.close()

class reactionrole:
    def __init__(self, msgid, emoji, roleid):
      self.msgid = msgid
      self.emoji = emoji
      self.roleid = roleid

SO, how to fix this error? should I go on with pickle or use another serialization technique? I could write to and parse a text file myself if needed.

1
did you use Google to check what is TaskStepMethWrapper? It shows that it part of asyncio and it unpickable. Probably it is in emoji_var. You should check what you have in emoji_var - print(emoji_var), print( type(emoji_var) ). And see if you need it or if you can get values from emoji_var as strings, list, dict, int which are pickleabelfuras
using Google I found similar problem Why is python pickle failing to dump dictionaries in 3.7 but also without solution.furas
@furas I'm not so sure about that because if the emoji is custom it'll give me an emoji object but if it's a normal global emoji then it's just a string with the emoji which I have been using normal emojis.VixieTSQ
it uses await and async so you may get some asyncio object instead of expected stringfuras
@furas I just ran type on emoji_var[0] and apparently it does give me an object. My bad I just made it a string and it works now thanks.VixieTSQ

1 Answers

1
votes

Turns out emoji_var[0] is an object. Simply using str() to turn it into a string fixed this.