Lobby
Lobbies contain a typed collection of Discord\Parts\Lobby\Member
objects in
$lobby->members
. The bot's $discord->lobbies
repository manages membership
through the Lobby HTTP API.
Naming a lobby
The bot's createLobby()
and modifyLobby()
methods and a player's
$session->lobbies->createOrJoin()
accept an optional name
in their data
array. Discord's stable OpenAPI schema allows a string of 1-100 characters or
explicit null
. The library forwards the value as supplied; omitting the key
does not send a name update.
$discord->lobbies->createLobby(['name' => 'Friday co-op']);
$discord->lobbies->modifyLobby($lobbyId, ['name' => 'Saturday co-op']);
$session->lobbies->createOrJoin('match-42', ['name' => 'Friday co-op']);
These are asynchronous requests that return promises resolving to lobby parts.
The create-or-join request uses the player's OAuth2 token; bot operations use
the bot token. The current Discord lobby response schema does not include
name
, so these request options do not imply a $lobby->name
property.
Updating the roster
$lobby->addMember($userId, ['additional_name' => 'Sir Lancelot'])
->then(function (\Discord\Parts\Lobby\Member $member) use ($lobby) {
// The lobby roster now includes the member returned by Discord.
echo $lobby->members->get('id', $member->id)->additional_name;
});
addMember()
also updates an existing member. removeMember()
removes a
member from the roster after Discord accepts the request. These methods update
both the supplied lobby object and the bot repository's cached lobby, when present.
Their promises wait for asynchronous cache reads and writes. Failed HTTP requests
leave the roster unchanged.
bulkUpdateMembers()
accepts arrays or member parts and returns a typed
collection of the members Discord added or updated:
$lobby->bulkUpdateMembers([
['id' => $userId, 'metadata' => ['team' => 'red']],
['id' => $departingUserId, 'remove_member' => true],
])->then(function ($upserted) {
// Removed users are not included in this collection.
});
Only returned upserts are added to the roster; users silently omitted by Discord
are not added or changed locally. Successful requested removals are applied, and
unrelated members are preserved. Omitting additional_name
preserves its remote
value, while sending null
clears it. Optional fields, including nullable
metadata
, are forwarded as supplied.
When called with an uncached lobby id, roster operations do not fetch the lobby or create a cache entry containing only the changed members. Fetch a complete lobby first when the application needs its roster.
Player sessions
Player operations use $session->lobbies
and the player's OAuth2 token. Each
session repository has its own cache namespace, including when the bot and several
players share one cache backend. Its cache is scoped to the repository instance;
a new session instance does not restore the previous instance's lobby cache.
Bot roster changes do not update other player repositories, and leaving a lobby
through one session does not evict it from another session or the bot repository.
For the distinction between server and client lobby management, see Discord's lobby guide.