对discord bot | discord.py使用pickle时出错

2024-09-27 00:21:11 发布

您现在位置:Python中文网/ 问答频道 /正文

当试图用pickle保存我的reactionrole对象列表时,会出现错误Command raised an exception: TypeError: cannot pickle 'TaskStepMethWrapper' object。 我没有尝试过任何东西,因为我不确定什么是TaskStepWrapper。这是我的密码:

@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

那么,如何修复这个错误呢?我应该继续使用pickle还是使用另一种序列化技术?如果需要,我可以自己编写和解析文本文件


Tags: theselfclientsendobjvarawaitpickle

热门问题