Python check user id in json file Python from strings

I don’t really know how to explain, so I will explain what I’m going to do.

  1. .profile <GrowID>, Insert GrowID that is in the json file.
  2. If GrowID in the file, open the user data

Here is what I have right now

Command Template

@client.command(aliases=["p"])
async def profile(ctx, GrowID=None):
  with open('account.json', 'r') as f:
    account = json.load(f)

  if GrowID == None:
    user = ctx.author

  elif not GrowID == None:
    user = client.get_user(GrowID.user_id)

  if str(user.id) in account:
    # <Codes>

My data in account.json

{
    "811510359289495572": {
        "Premium": false,
        "GrowID": "Dec7h7alker",
        "Character": "Default",
        "Level": 1,
        "XP": 0,
        "XPLevel": 150,
        "Gems": 0,
        "World Locks": 0,
        "Diamond Locks": 0,
        "Growtokens": 0
    }
}

Command to add the data

@client.command()
async def start(ctx):
        with open('account.json', 'r') as f:
          account = json.load(f)
        user = ctx.author

        if str(user.id) in account:
                await ctx.send("Your account has already existed!")

        elif str(user.id) not in account:
                account[str(user.id)] = {}
                account[str(user.id)]["Premium"] = False
                account[str(user.id)]["GrowID"] = user.name
                account[str(user.id)]["Character"] = "Default"
                account[str(user.id)]["Level"] = 1
                account[str(user.id)]["XP"] = 0
                account[str(user.id)]["XPLevel"] = 150
                account[str(user.id)]["Gems"] = 0
                account[str(user.id)]["World Locks"] = 0
                account[str(user.id)]["Diamond Locks"] = 0
                account[str(user.id)]["Growtokens"] = 0

                with open('account.json', 'w') as f:
                        json.dump(account, f, indent=4)

    # <codes (not needed cuz its just sending message)>

There you go

Answer

I really don’t understand where the problem is, because as already mentioned in the comments you can use your already existing code to retrieve data from the user.

But for that we first assume that GrowID depends on discord.Member, otherwise it won’t work.

Then we build our command on top of that:

@client.command(aliases=["p"])
async def profile(ctx, GrowID: discord.Member = None):
    with open('channel.json', 'r') as f:
        account = json.load(f) # Load account

        if GrowID == None:
            user = ctx.author
            await ctx.send(account[str(user.id)]) # Retrieve and send data

        else:
            user1 = client.get_user(GrowID.id) # Get the ID of the named user.
            await ctx.send(account[str(user1.id)]) # Send data of the account

You will then be sent the following about the user:

{'Premium': False, 'GrowID': 'Dec7h7alker', 'Character': 'Default', 'Level': 1, 'XP': 0, 'XPLevel': 150, 'Gems': 0, 'World Locks': 0, 'Diamond Locks': 0, 'Growtokens': 0}

To make this more user friendly then your knowledge is needed, because this has nothing to do with the question anymore.

How the command works:

enter image description here