Session
in package
Acts as one user, with their own OAuth2 token rather than the bot's.
This is how a game's backend does what the Social SDK does for a player:
joining a lobby, chatting in it, linking a channel. Sessions come from
SessionManager — $discord->sessions — which opens, stores, resumes
and refreshes them.
Each session has its own HTTP client, because Discord rate-limits each token separately, but shares the bot's driver and connection pool.
Tags
Table of Contents
Properties
- $discord : Discord
- $http : Http
- $key : ?string
- $lobbies : SessionLobbyRepository
- $token : AccessToken
Methods
- __construct() : mixed
- __debugInfo() : array<string, mixed>
- __get() : mixed
- Exposes the read-only `lobbies` repository.
- getApplicationRoleConnection() : PromiseInterface<string|int, ApplicationRoleConnection>
- Returns the user's role connection for an application. Requires the `role_connections.write` scope.
- getConnections() : PromiseInterface<string|int, ExCollectionInterface<string|int, Connection>|array<string|int, Connection>>
- Returns the user's connected accounts. Requires the `connections` scope.
- getCurrentUser() : PromiseInterface<string|int, User>
- Returns the user the token belongs to.
- getEntitlements() : PromiseInterface<string|int, ExCollectionInterface<string|int, Entitlement>|array<string|int, Entitlement>>
- Returns the user's entitlements for an application.
- getHttpClient() : Http
- The HTTP client that sends the user's token.
- getKey() : ?string
- What the token is stored under, or null if it is not stored.
- getToken() : AccessToken
- The user's token.
- updateApplicationRoleConnection() : PromiseInterface<string|int, ApplicationRoleConnection>
- Updates the user's role connection for an application. Requires the `role_connections.write` scope.
- clientFor() : Http
- A client that sends this token, sharing the bot's driver.
- collect() : ExCollectionInterface
- Hydrates a list of parts into a collection.
- forApplication() : PromiseInterface
- Runs a request for an application given as a part or an id, or for the bot's own.
Properties
$discord
protected
Discord
$discord
$http
protected
Http
$http
$key
protected
?string
$key
= null
$lobbies
protected
SessionLobbyRepository
$lobbies
$token
protected
AccessToken
$token
Methods
__construct()
public
__construct(Discord $discord, AccessToken $token[, string|null $key = null ]) : mixed
Parameters
- $discord : Discord
-
The client.
- $token : AccessToken
-
The user's token.
- $key : string|null = null
-
What the token is stored under, if it is stored.
__debugInfo()
public
__debugInfo() : array<string, mixed>
Return values
array<string, mixed>__get()
Exposes the read-only `lobbies` repository.
public
__get(string $name) : mixed
Parameters
- $name : string
getApplicationRoleConnection()
Returns the user's role connection for an application. Requires the `role_connections.write` scope.
public
getApplicationRoleConnection([Application|string|null $application = null ]) : PromiseInterface<string|int, ApplicationRoleConnection>
Parameters
- $application : Application|string|null = null
-
The application or its id; the bot's own if omitted.
Tags
Return values
PromiseInterface<string|int, ApplicationRoleConnection>getConnections()
Returns the user's connected accounts. Requires the `connections` scope.
public
getConnections() : PromiseInterface<string|int, ExCollectionInterface<string|int, Connection>|array<string|int, Connection>>
Tags
Return values
PromiseInterface<string|int, ExCollectionInterface<string|int, Connection>|array<string|int, Connection>>getCurrentUser()
Returns the user the token belongs to.
public
getCurrentUser() : PromiseInterface<string|int, User>
Tags
Return values
PromiseInterface<string|int, User>getEntitlements()
Returns the user's entitlements for an application.
public
getEntitlements([Application|string|null $application = null ]) : PromiseInterface<string|int, ExCollectionInterface<string|int, Entitlement>|array<string|int, Entitlement>>
Parameters
- $application : Application|string|null = null
-
The application or its id; the bot's own if omitted.
Tags
Return values
PromiseInterface<string|int, ExCollectionInterface<string|int, Entitlement>|array<string|int, Entitlement>>getHttpClient()
The HTTP client that sends the user's token.
public
getHttpClient() : Http
Return values
HttpgetKey()
What the token is stored under, or null if it is not stored.
public
getKey() : ?string
Return values
?stringgetToken()
The user's token.
public
getToken() : AccessToken
Return values
AccessTokenupdateApplicationRoleConnection()
Updates the user's role connection for an application. Requires the `role_connections.write` scope.
public
updateApplicationRoleConnection(?array<string|int, mixed> $connection[, Application|string|null $application = null ]) : PromiseInterface<string|int, ApplicationRoleConnection>
Parameters
- $connection : ?array<string|int, mixed>
-
['metadata'] Metadata keys mapped to their string values (max 100 characters each).
- $application : Application|string|null = null
-
The application or its id; the bot's own if omitted.
Tags
Return values
PromiseInterface<string|int, ApplicationRoleConnection>clientFor()
A client that sends this token, sharing the bot's driver.
protected
clientFor(AccessToken $token) : Http
Parameters
- $token : AccessToken
Return values
Httpcollect()
Hydrates a list of parts into a collection.
protected
collect(string $class, object|array<string|int, mixed> $response) : ExCollectionInterface
Parameters
- $class : string
- $response : object|array<string|int, mixed>
Return values
ExCollectionInterfaceforApplication()
Runs a request for an application given as a part or an id, or for the bot's own.
protected
forApplication(Application|string|null $application, callable(string): PromiseInterface $request) : PromiseInterface
Parameters
- $application : Application|string|null
- $request : callable(string): PromiseInterface
-
Given the application id.