尝试使用python为Discord机器人创建用户个人资料,如果他们已经有一个帐户,则将其删除

时间:2020-09-29 18:07:55

标签: python discord.py

因此,我正在制作一个使用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.")

0 个答案:

没有答案