尝试使用python为discord bot创建用户配置文件,如果他们已经拥有一个帐户,则该帐户将被删除
所以我制作了一个使用python的discord机器人,我试图创建特定于用户的配置文件,但是如果用户已经有一个配置文件,它会删除他们的配置文件,但会保留该文件?有什么想法吗尝试使用python为discord bot创建用户配置文件,如果他们已经拥有一个帐户,则该帐户将被删除,python,discord.py,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(
@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.")