DiscordPHP Documentation

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
since
10.59.0

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

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
link
https://docs.discord.com/developers/resources/user#get-current-user-application-role-connection
Return values
PromiseInterface<string|int, ApplicationRoleConnection>

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
link
https://docs.discord.com/developers/resources/entitlement
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
Http

getKey()

What the token is stored under, or null if it is not stored.

public getKey() : ?string
Return values
?string

updateApplicationRoleConnection()

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
link
https://docs.discord.com/developers/resources/user#update-current-user-application-role-connection
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
Http

collect()

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
ExCollectionInterface

forApplication()

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.

Return values
PromiseInterface
On this page

Search results