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

async def profile(ctx, GrowID=None):
  with open('account.json', 'r') as f:
    account = json.load(f)

  if GrowID == None:
    user =

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

  if str( 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

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

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

        elif str( not in account:
                account[str(] = {}
                account[str(]["Premium"] = False
                account[str(]["GrowID"] =
                account[str(]["Character"] = "Default"
                account[str(]["Level"] = 1
                account[str(]["XP"] = 0
                account[str(]["XPLevel"] = 150
                account[str(]["Gems"] = 0
                account[str(]["World Locks"] = 0
                account[str(]["Diamond Locks"] = 0
                account[str(]["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


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:

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 =
            await ctx.send(account[str(]) # Retrieve and send data

            user1 = client.get_user( # Get the ID of the named user.
            await ctx.send(account[str(]) # 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