Hey there!
Recently I’ve bumped into an error whilst developing my Discord Bot, where the Bot gets a player’s current game (in this case, getting it and printing it in console)
When using the following API: ‘https://presence.roblox.com/v1/presence/users’
Everything after (including) PlaceId is null.
[ I’m using node.Js for this! ]
Here’s an image of the output of my code, where I’ve used some console.log statements
Presence type 0 is Offline. I understand why ‘null’ for game details is provided here.
However, Presence type 2 (In-game) presents ‘null’.
My script includes this snippet:
const roGeoLocate = async (userId) => {
const url = 'https://presence.roblox.com/v1/presence/users';
const headers = {
//'Content-Type': 'application/json',
'x-api-key': ROBLOX_API, // Ensure this is correctly set
};
const body = {
userIds: [userId],
};
try {
const response = await axios.post(url, body, { headers });
if (response.status === 200 && response.data.userPresences.length > 0) {
const userPresence = response.data.userPresences[0];
console.log(chalk.magenta(JSON.stringify(response.data.userPresences[0], null, 2)));
console.log(chalk.red(JSON.stringify(response.data, null, 2)));
console.log(chalk.green(JSON.stringify(response.data.userPresences, null, 2)));
return {
userId: userPresence.userId,
presenceType: userPresence.userPresenceType, // 0: Offline, 1: Online, 2: In-Game, 3: In-Studio
lastLocation: userPresence.lastLocation,
placeId: userPresence.placeId,
rootPlaceId: userPresence.rootPlaceId,
gameId: userPresence.gameId,
universeId: userPresence.universeId,
lastOnline: userPresence.lastOnline,
invisibleMode: userPresence.invisibleModeExpiry,
};
} else {
console.error('Error fetching user presence: Unexpected response format.');
return null;
}
} catch (error) {
console.error(`Error fetching user presence: ${error.message}`);
return null;
}
};
What the script SHOULD do is output in a print statement the gameId & other info of the ‘experience’ the player is in.
Regarding testing, I’ve used my own User (Converted to UserId), and played a Publicly available game. My ‘Who can join me’ settings are set to ‘Everyone’.
Regarding solutions, I’ve looked into some more posts of the Forum, external websites, and more, however most of them were not much help.
I’ve also used AI assistants such as GitHub Copilot (Pro) & ChatGPT (o3/4o), however no matter the format, the script still returned ‘null’.
It’d be some great help if someone could provide some assistance here, and why this isn’t working as expected.
TL;DR:
- Trying to make a script that gets a User’s current game with the Presence API
- Script returns ‘null’ for what I want, but other aspects work and are printed (eg UserId)
