Skip to content

presence

This module contains classes intended to parse and deal with data from Roblox presence endpoints.

Presence

Represents a user's presence.

Attributes:

Name Type Description
user_presence_type PresenceType

The type of the presence.

last_location str

A string representing the user's last location.

place Optional[BasePlace]

The place the user is playing or editing.

root_place Optional[BasePlace]

The root place of the parent universe of the last place the user is playing or editing.

job Optional[BaseJob]

The job of the root place that the user is playing or editing.

universe Optional[BaseUniverse]

The universe the user is playing or editing.

last_online datetime

When the user was last online.

user BaseUser

The user this presence belongs to.

Source code in roblox/presence.py
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
class Presence:
    """
    Represents a user's presence.

    Attributes:
        user_presence_type: The type of the presence.
        last_location: A string representing the user's last location.
        place: The place the user is playing or editing.
        root_place: The root place of the parent universe of the last place the user is playing or editing.
        job: The job of the root place that the user is playing or editing.
        universe: The universe the user is playing or editing.
        last_online: When the user was last online.
        user: The user this presence belongs to.
    """

    def __init__(self, client: Client, data: dict):
        """
        Arguments:
            client: Client object.
            data: The data from the request.
        """
        self._client: Client = client

        self.user_presence_type: PresenceType = PresenceType(data["userPresenceType"])
        self.last_location: str = data["lastLocation"]

        self.place: Optional[BasePlace] = BasePlace(
            client=client,
            place_id=data["placeId"]
        ) if data.get("placeId") else None

        self.root_place: Optional[BasePlace] = BasePlace(
            client=client,
            place_id=data["rootPlaceId"]
        ) if data.get("rootPlaceId") else None

        self.job: Optional[BaseJob] = BaseJob(self._client, data["gameId"]) if data.get("gameId") else None

        self.universe: Optional[BaseUniverse] = BaseUniverse(
            client=client,
            universe_id=data["universeId"]
        ) if data.get("universeId") else None

        self.user: BaseUser = client.get_base_user(data["userId"])
        self.last_online: datetime = parse(data["lastOnline"])

    def __repr__(self):
        return f"<{self.__class__.__name__} user_presence_type={self.user_presence_type}>"

__init__(client, data)

Parameters:

Name Type Description Default
client Client

Client object.

required
data dict

The data from the request.

required
Source code in roblox/presence.py
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
def __init__(self, client: Client, data: dict):
    """
    Arguments:
        client: Client object.
        data: The data from the request.
    """
    self._client: Client = client

    self.user_presence_type: PresenceType = PresenceType(data["userPresenceType"])
    self.last_location: str = data["lastLocation"]

    self.place: Optional[BasePlace] = BasePlace(
        client=client,
        place_id=data["placeId"]
    ) if data.get("placeId") else None

    self.root_place: Optional[BasePlace] = BasePlace(
        client=client,
        place_id=data["rootPlaceId"]
    ) if data.get("rootPlaceId") else None

    self.job: Optional[BaseJob] = BaseJob(self._client, data["gameId"]) if data.get("gameId") else None

    self.universe: Optional[BaseUniverse] = BaseUniverse(
        client=client,
        universe_id=data["universeId"]
    ) if data.get("universeId") else None

    self.user: BaseUser = client.get_base_user(data["userId"])
    self.last_online: datetime = parse(data["lastOnline"])

PresenceProvider

The PresenceProvider is an object that represents https://presence.roblox.com/ and provides multiple functions for fetching user presence information.

Source code in roblox/presence.py
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
class PresenceProvider:
    """
    The PresenceProvider is an object that represents https://presence.roblox.com/ and provides multiple functions
    for fetching user presence information.
    """

    def __init__(self, client: Client):
        self._client: Client = client

    async def get_user_presences(self, users: List[UserOrUserId]) -> List[Presence]:
        """
        Grabs a list of Presence objects corresponding to each user in the list.

        Arguments:
            users: The list of users you want to get Presences from.

        Returns:
            A list of Presences.
        """

        presences_response = await self._client.requests.post(
            url=self._client.url_generator.get_url("presence", "v1/presence/users"),
            json={
                "userIds": list(map(int, users))
            }
        )
        presences_data = presences_response.json()["userPresences"]
        return [Presence(client=self._client, data=presence_data) for presence_data in presences_data]

get_user_presences(users) async

Grabs a list of Presence objects corresponding to each user in the list.

Parameters:

Name Type Description Default
users List[UserOrUserId]

The list of users you want to get Presences from.

required

Returns:

Type Description
List[Presence]

A list of Presences.

Source code in roblox/presence.py
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
async def get_user_presences(self, users: List[UserOrUserId]) -> List[Presence]:
    """
    Grabs a list of Presence objects corresponding to each user in the list.

    Arguments:
        users: The list of users you want to get Presences from.

    Returns:
        A list of Presences.
    """

    presences_response = await self._client.requests.post(
        url=self._client.url_generator.get_url("presence", "v1/presence/users"),
        json={
            "userIds": list(map(int, users))
        }
    )
    presences_data = presences_response.json()["userPresences"]
    return [Presence(client=self._client, data=presence_data) for presence_data in presences_data]

PresenceType

Bases: IntEnum

Represents a user's presence type.

Source code in roblox/presence.py
26
27
28
29
30
31
32
33
class PresenceType(IntEnum):
    """
    Represents a user's presence type.
    """
    offline = 0
    online = 1
    in_game = 2
    in_studio = 3