如何将每个用户保存到不协调的json文件中



我目前拥有的代码并不是作为json文件提供给所有用户的,它存储了"硬币";in仅将其保存为userid。这是用于将硬币存储在json文件中的代码:

@client.command()
async def Shibaku1(ctx, coin1, coin2, coin3, coin4, coin5, coin6):
with open('Shibaku1.json', 'r') as f:
coins_data = json.load(f)
coins_data['userid'] = (coin1, coin2, coin3, coin4, coin5, coin6)
with open('Shibaku1.json', 'w') as f:
json.dump(coins_data, f)

json文件中存储的内容示例:

{"userid": [":Helicopter:", ":Skateboard1:", ":swords:", ":mace:", ":mace:", ":mangosteen:"]}

我如何使它为每个用户存储不同的集合?

coins_data['userid']替换为coins_data[str(ctx.author.id)]

然后您的json文件将如下所示:

{"123456789": [":Helicopter:", ":Skateboard1:", ":swords:", ":mace:", ":mace:", ":mangosteen:"]}

最新更新