How can I access data about what game a user is currently playing?

Is there like an API I could use to access said data above?
For context, I’m trying to make a discord app command ( a / command) where anyone executing the command can find what game I’m playing and would send a link to the game however every time time I’ve tried to implement this command it always fails giving errors such as:

Failed to check presence (Status 404)
Error: {"errors":[{"code":0,"message":""}]}

Now I’m unsure if the methods I was using to get this data was deprecated, Some of the code was AI generated as I used AI to debug the code.

This was my def to get the .json and I assume the .json would contain the data I needed to get the game that I was playing:

async def get_json(session, url, method="GET", json_body=None):
    try:
        timeout = aiohttp.ClientTimeout(total=5)  
        if method == "GET":
            async with session.get(url, timeout=timeout) as resp:
                if resp.status != 200:
                    return None
                return await resp.json()
        elif method == "POST":
            async with session.post(url, json=json_body, timeout=timeout) as resp:
                if resp.status != 200:
                    return None
                return await resp.json()
    except asyncio.TimeoutError:
        print(f"Timeout fetching {url}")
        return None
    except Exception as e:
        print(f"HTTP request error fetching {url}: {e}")
        return None

To get stuff like the URL I used "https://presence.roblox.com/v1/presence/users" and https://games.roblox.com/v1/places/{place_id}" and I’m unsure if those are deprecated too

The full code snippets are here:

async def get_roblox_user_game(session, user_id):
    url = "https://presence.roblox.com/v1/presence/users"
    json_body = {"userIds": [user_id]}
    data = await get_json(session, url, method="POST", json_body=json_body)
    if not data:
        return None
    presences = data.get("userPresences", [])
    if not presences:
        return None
    presence = presences[0]
    return presence.get("placeId")

async def get_place_details(session, place_id):
    url = f"https://games.roblox.com/v1/places/{place_id}"
    return await get_json(session, url)

So in summary, is there an alternative, maybe more simplier way to get this information? I’ve already tried to use things such as API keys but I will be honest I have no clue what I’m doing when It comes to APIs.

Can you please try printing out the the user id, as well as the json_body and url at various points?

I tested out your code with the get_roblox_user_game (although I used requests instead of aiohttps, just so I dont have to deal with the async stuff), and the program was able to run perfectly fine.

From what I could tell by using prints is that get_json() seems to not be called at all? because it never prints the URL

Here are the defs where I printed my JSON body and user ID:

async def get_roblox_user_game(session, user_id):
    print(f"Fetching game for user ID: {user_id}")
    url = "https://presence.roblox.com/v1/presence/users"
    json_body = {"userIds": [user_id]}
    data = await get_json(session, url, method="POST", json_body=json_body)
    print("Json body:", json_body)
    if not data:
        return None
    presences = data.get("userPresences", [])
    if not presences:
        return None
    presence = presences[0]
    return presence.get("placeId")

And User ID:

async def get_roblox_user_game(session, user_id):
    print(f"Fetching game for user ID: {user_id}")
    url = "https://presence.roblox.com/v1/presence/users"
    json_body = {"userIds": [user_id]}
    data = await get_json(session, url, method="POST", json_body=json_body)
    print("Json body:", json_body)
    if not data:
        return None
    presences = data.get("userPresences", [])
    if not presences:
        return None
    presence = presences[0]
    return presence.get("placeId")