因此,我正在制作一个使用python的discord机器人,并尝试创建用户特定的配置文件,但是如果用户已经有一个配置文件,它会删除其配置文件,但会保留文件?有什么想法吗?
@client.command()
async def create(ctx):
user_id = ctx.author.id
path = f"users/{user_id}.json"
if not os.path.exists(path):
with open(path, "w") as f:
user_start = {
"id": user_id,
"level": 1,
"health": 100,
"exp": 0,
"weaponid": 1
}
print(json.dumps(user_start),file=f)
await ctx.send("Account created.")
else:
await ctx.send("Account already exists.")