这是我的密码
with open('setting1.json',mode='r',encoding='utf8')as jfile:
jdata = json.load(jfile)
@bot.command(pass_context=True)
async def data(ctx):
a1=[]
author=ctx.message.author
a1.append(author)
jdata["a1"]=a1
with open('setting1.json',mode='w',encoding='utf8')as jfile:
json.dump(jdata,jfile)
我想用json保存成员数据,并运行以下代码:
TypeError: Object of type 'Member' is not JSON serializable
我怎样才能修复它(或者根本不可能)?谢谢
错误显示“TypeError:type'Member'的对象不可JSON序列化”。看起来discord.py返回的是'Member'类型,而不是字符串类型。要解决这个问题,只需将变量'author'转换为字符串,方法是将表示
author = ctx.message.author
的行转换为author = str(ctx.message.author)
。这就是修复该错误所需的全部操作。但我想我会这么做的相关问题 更多 >
编程相关推荐