当尝试用泡菜保存我的反应容器对象列表时,出现错误Command raised an exception: TypeError: cannot pickle 'TaskStepMethWrapper' object
。
我没有尝试任何操作,因为我不确定TaskStepMethWrapper是什么。这是我的代码:
@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还是使用其他序列化技术?如果需要,我可以自己编写和解析文本文件。
答案 0 :(得分:1)
结果emoji_var [0]是一个对象。只需使用str()
将其转换为字符串即可解决此问题。