Discord
in package
Uses
EventEmitterTrait
The Discord client class.
Tags
Table of Contents
- GATEWAY_VERSION = 10
- The gateway version the client uses.
- VERSION = 'v10.0.0'
- The client version.
- $application : Application
- $avatar : string
- $avatar_hash : string
- $bot : bool
- $discriminator : string
- $email : string
- $guilds : GuildRepository
- $id : string
- $password : string
- $private_channels : PrivateChannelRepository
- $user : User
- $username : string
- $users : UserRepository
- $verified : bool
- $cacheConfig : CacheConfig
- The cache configuration.
- $client : Client
- The Client class.
- $closing : bool
- Whether the client is closing.
- $connected : bool
- Whether the client is connected to the gateway.
- $emittedInit : bool
- Whether `init` has been emitted.
- $encoding : string
- What encoding the client will use, either `json` or `etf`.
- $factory : Factory
- The part/repository factory.
- $gateway : string
- The gateway URL that the WebSocket client will connect to.
- $handlers : Handlers
- The event handlers.
- $heartbeatAckTimer : TimerInterface
- The timer that resends the heartbeat packet if a HEARTBEAT_ACK packet is not received in 5 seconds.
- $heartbeatInterval : int
- The heartbeat interval.
- $heartbeatTime : int
- The time that the last heartbeat packet was sent.
- $heartbeatTimer : TimerInterface
- The timer that sends the heartbeat packet.
- $http : Http
- The HTTP client.
- $largeGuilds : array<string|int, mixed>
- An array of large guilds that need to be requested for members.
- $largeSent : array<string|int, mixed>
- An array of large guilds that have been requested for members.
- $logger : LoggerInterface
- The logger.
- $loop : LoopInterface
- The ReactPHP event loop.
- $options : array<string|int, mixed>
- An array of options passed to the client.
- $payloadBuffer : string
- Gateway compressed message payload buffer.
- $payloadCount : int
- Tracks the number of payloads the client has sent in the past 60 seconds.
- $payloadTimer : TimerInterface
- Payload count reset timer.
- $reconnectCount : int
- How many times the client has reconnected.
- $reconnecting : bool
- Whether the client is currently reconnecting.
- $resume_gateway_url : string
- The resume_gateway_url that the WebSocket client will reconnect to.
- $seq : int
- The packet sequence that the client is up to.
- $sessionId : string
- The session ID of the current session.
- $token : string
- The authentication token.
- $unparsedPackets : array<string|int, mixed>
- An array of unparsed packets.
- $voiceClients : array<string|int, mixed>
- An array of voice clients that are currently connected.
- $voiceLoggers : array<string|int, mixed>
- An array of loggers for voice clients.
- $ws : WebSocket
- The WebSocket instance.
- $wsFactory : Connector
- The WebSocket client factory.
- $zlibDecompressor : InflateContext|false
- zlib decompressor.
- $application_commands : array<string|int, RegisteredCommand>
- An array of registered slash commands.
- __call() : mixed
- Handles dynamic calls to the client.
- __construct() : mixed
- Creates a Discord client instance.
- __debugInfo() : array<string|int, mixed>
- Returns an array that can be used to describe the internal state of this object.
- __get() : mixed
- Handles dynamic get calls to the client.
- __set() : void
- Handles dynamic set calls to the client.
- addLargeGuild() : void
- Adds a large guild to the large guild array.
- close() : void
- Closes the Discord client.
- factory() : Part|AbstractRepository
- Allows access to the part/repository factory.
- getCacheConfig() : CacheConfig
- Gets the cache configuration.
- getChannel() : Channel|null
- Gets a channel.
- getFactory() : Factory
- Gets the factory.
- getHttp() : Http
- Gets the HTTP client.
- getHttpClient() : Http
- Gets the HTTP client.
- getLogger() : LoggerInterface
- Gets the logger being used.
- getLoop() : LoopInterface
- Gets the loop being used by the client.
- getVoiceClient() : VoiceClient|null
- Gets a voice client from a guild ID. Returns null if there is no voice client.
- handleWsClose() : void
- Handles WebSocket closes received by the client.
- handleWsConnection() : void
- Handles WebSocket connections received by the client.
- handleWsConnectionFailed() : mixed
- Handles cases when the WebSocket cannot be connected to.
- handleWsError() : void
- Handles WebSocket errors received by the client.
- handleWsMessage() : void
- Handles WebSocket messages received by the client.
- heartbeat() : void
- Sends a heartbeat packet to the Discord gateway.
- joinVoiceChannel() : PromiseInterface
- Joins a voice channel.
- listenCommand() : RegisteredCommand
- Add listerner for incoming application command from interaction.
- run() : void
- Starts the ReactPHP event loop.
- updatePresence() : void
- Updates the clients presence.
- connectWs() : void
- Initializes the connection with the Discord gateway.
- handleDispatch() : void
- Handles dispatch events received by the WebSocket.
- handleGuildMembersChunk() : void
- Handles `GUILD_MEMBERS_CHUNK` packets.
- handleHeartbeat() : void
- Handles heartbeat packets received by the client.
- handleHeartbeatAck() : void
- Handles heartbeat ACK packets received by the client.
- handleHello() : void
- Handles HELLO packets received by the websocket.
- handleInvalidSession() : void
- Handles invalid session packets received by the client.
- handleReady() : false|void
- Handles `READY` packets.
- handleReconnect() : void
- Handles reconnect packets received by the client.
- handleResume() : void
- Handles `RESUME` packets.
- handleVoiceServerUpdate() : void
- Handles `VOICE_SERVER_UPDATE` packets.
- handleVoiceStateUpdate() : void
- Handles `VOICE_STATE_UPDATE` packets.
- identify() : bool
- Identifies with the Discord gateway with `IDENTIFY` or `RESUME` packets.
- processWsMessage() : void
- Process WebSocket message payloads.
- ready() : false|void
- Emits init if it has not been emitted already.
- resolveOptions() : array<string|int, mixed>
- Resolves the options.
- send() : void
- Sends a packet to the Discord gateway.
- setGateway() : ExtendedPromiseInterface
- Retrieves and sets the gateway URL for the client.
- setupChunking() : false|void
- Sets guild member chunking up.
- setupHeartbeat() : void
- Sets the heartbeat timer up.
Constants
GATEWAY_VERSION
The gateway version the client uses.
public
int
GATEWAY_VERSION
= 10
Gateway version.
VERSION
The client version.
public
string
VERSION
= 'v10.0.0'
Version.
Properties
$application
public
Application
$application
The OAuth2 application of the bot.
$avatar
public
string
$avatar
The avatar URL of the client.
$avatar_hash
public
string
$avatar_hash
The avatar hash of the client.
$bot
public
bool
$bot
Whether the client is a bot.
$discriminator
public
string
$discriminator
The unique discriminator of the client.
public
string
$email
The email of the client.
$guilds
public
GuildRepository
$guilds
$id
public
string
$id
The unique identifier of the client.
$password
public
string
$password
The password of the client (if they have provided it).
$private_channels
public
PrivateChannelRepository
$private_channels
$user
public
User
$user
The user instance of the client.
$username
public
string
$username
The username of the client.
$users
public
UserRepository
$users
$verified
public
bool
$verified
Whether the client has verified their email.
$cacheConfig
The cache configuration.
protected
CacheConfig
$cacheConfig
$client
The Client class.
protected
Client
$client
Discord client.
$closing
Whether the client is closing.
protected
bool
$closing
= false
Closing.
$connected
Whether the client is connected to the gateway.
protected
bool
$connected
= false
Connected.
$emittedInit
Whether `init` has been emitted.
protected
bool
$emittedInit
= false
Emitted.
$encoding
What encoding the client will use, either `json` or `etf`.
protected
string
$encoding
= 'json'
Encoding.
$factory
The part/repository factory.
protected
Factory
$factory
Part factory.
$gateway
The gateway URL that the WebSocket client will connect to.
protected
string
$gateway
Gateway URL.
$handlers
The event handlers.
protected
Handlers
$handlers
Handlers.
$heartbeatAckTimer
The timer that resends the heartbeat packet if a HEARTBEAT_ACK packet is not received in 5 seconds.
protected
TimerInterface
$heartbeatAckTimer
Timer.
$heartbeatInterval
The heartbeat interval.
protected
int
$heartbeatInterval
Heartbeat interval.
$heartbeatTime
The time that the last heartbeat packet was sent.
protected
int
$heartbeatTime
Epoch time.
$heartbeatTimer
The timer that sends the heartbeat packet.
protected
TimerInterface
$heartbeatTimer
Timer.
$http
The HTTP client.
protected
Http
$http
Client.
$largeGuilds
An array of large guilds that need to be requested for members.
protected
array<string|int, mixed>
$largeGuilds
= []
Large guilds.
$largeSent
An array of large guilds that have been requested for members.
protected
array<string|int, mixed>
$largeSent
= []
Large guilds.
$logger
The logger.
protected
LoggerInterface
$logger
Logger.
$loop
The ReactPHP event loop.
protected
LoopInterface
$loop
Event loop.
$options
An array of options passed to the client.
protected
array<string|int, mixed>
$options
Options.
$payloadBuffer
Gateway compressed message payload buffer.
protected
string
$payloadBuffer
= ''
Buffer.
$payloadCount
Tracks the number of payloads the client has sent in the past 60 seconds.
protected
int
$payloadCount
= 0
$payloadTimer
Payload count reset timer.
protected
TimerInterface
$payloadTimer
$reconnectCount
How many times the client has reconnected.
protected
int
$reconnectCount
= 0
Reconnect count.
$reconnecting
Whether the client is currently reconnecting.
protected
bool
$reconnecting
= false
Reconnecting.
$resume_gateway_url
The resume_gateway_url that the WebSocket client will reconnect to.
protected
string
$resume_gateway_url
resume_gateway_url URL.
$seq
The packet sequence that the client is up to.
protected
int
$seq
Sequence.
$sessionId
The session ID of the current session.
protected
string
$sessionId
Session ID.
$token
The authentication token.
protected
string
$token
Token.
$unparsedPackets
An array of unparsed packets.
protected
array<string|int, mixed>
$unparsedPackets
= []
Unparsed packets.
$voiceClients
An array of voice clients that are currently connected.
protected
array<string|int, mixed>
$voiceClients
= []
Voice Clients.
$voiceLoggers
An array of loggers for voice clients.
protected
array<string|int, mixed>
$voiceLoggers
= []
Loggers.
$ws
The WebSocket instance.
protected
WebSocket
$ws
Instance.
$wsFactory
The WebSocket client factory.
protected
Connector
$wsFactory
Factory.
$zlibDecompressor
zlib decompressor.
protected
InflateContext|false
$zlibDecompressor
$application_commands
An array of registered slash commands.
private
array<string|int, RegisteredCommand>
$application_commands
Methods
__call()
Handles dynamic calls to the client.
public
__call(string $name, array<string|int, mixed> $params) : mixed
Parameters
- $name : string
-
Function name.
- $params : array<string|int, mixed>
-
Function paramaters.
Return values
mixed —__construct()
Creates a Discord client instance.
public
__construct([array<string|int, mixed> $options = [] ]) : mixed
Parameters
- $options : array<string|int, mixed> = []
-
Array of options.
Tags
Return values
mixed —__debugInfo()
Returns an array that can be used to describe the internal state of this object.
public
__debugInfo() : array<string|int, mixed>
Return values
array<string|int, mixed> —__get()
Handles dynamic get calls to the client.
public
__get(string $name) : mixed
Parameters
- $name : string
-
Variable name.
Return values
mixed —__set()
Handles dynamic set calls to the client.
public
__set(string $name, mixed $value) : void
Parameters
- $name : string
-
Variable name.
- $value : mixed
-
Value to set.
Return values
void —addLargeGuild()
Adds a large guild to the large guild array.
public
addLargeGuild(Guild $guild) : void
Parameters
- $guild : Guild
-
The guild.
Return values
void —close()
Closes the Discord client.
public
close([bool $closeLoop = true ]) : void
Parameters
- $closeLoop : bool = true
-
Whether to close the loop as well. Default true.
Return values
void —factory()
Allows access to the part/repository factory.
public
factory(string $class[, mixed $data = [] ][, bool $created = false ]) : Part|AbstractRepository
Parameters
- $class : string
-
The class to build.
- $data : mixed = []
-
Data to create the object.
- $created : bool = false
-
Whether the object is created (if part).
Tags
Return values
Part|AbstractRepository —getCacheConfig()
Gets the cache configuration.
public
getCacheConfig([mixed $repository_class = AbstractRepository::class ]) : CacheConfig
Parameters
- $repository_class : mixed = AbstractRepository::class
Return values
CacheConfig —getChannel()
Gets a channel.
public
getChannel(string|int $channel_id) : Channel|null
Parameters
- $channel_id : string|int
-
Id of the channel.
Return values
Channel|null —getFactory()
Gets the factory.
public
getFactory() : Factory
Return values
Factory —getHttp()
Gets the HTTP client.
public
getHttp() : Http
Tags
Return values
Http —getHttpClient()
Gets the HTTP client.
public
getHttpClient() : Http
Return values
Http —getLogger()
Gets the logger being used.
public
getLogger() : LoggerInterface
Return values
LoggerInterface —getLoop()
Gets the loop being used by the client.
public
getLoop() : LoopInterface
Return values
LoopInterface —getVoiceClient()
Gets a voice client from a guild ID. Returns null if there is no voice client.
public
getVoiceClient(string $guild_id) : VoiceClient|null
Parameters
- $guild_id : string
-
The guild ID to look up.
Return values
VoiceClient|null —handleWsClose()
Handles WebSocket closes received by the client.
public
handleWsClose(int $op, string $reason) : void
Parameters
- $op : int
-
The close code.
- $reason : string
-
The reason the WebSocket closed.
Return values
void —handleWsConnection()
Handles WebSocket connections received by the client.
public
handleWsConnection(WebSocket $ws) : void
Parameters
- $ws : WebSocket
-
WebSocket client.
Return values
void —handleWsConnectionFailed()
Handles cases when the WebSocket cannot be connected to.
public
handleWsConnectionFailed(Throwable $e) : mixed
Parameters
- $e : Throwable
Return values
mixed —handleWsError()
Handles WebSocket errors received by the client.
public
handleWsError(Exception $e) : void
Parameters
- $e : Exception
-
The error.
Return values
void —handleWsMessage()
Handles WebSocket messages received by the client.
public
handleWsMessage(Message $message) : void
Parameters
- $message : Message
-
Message object.
Return values
void —heartbeat()
Sends a heartbeat packet to the Discord gateway.
public
heartbeat() : void
Return values
void —joinVoiceChannel()
Joins a voice channel.
public
joinVoiceChannel(Channel $channel[, bool $mute = false ][, bool $deaf = true ][, LoggerInterface|null $logger = null ][, bool $check = true ]) : PromiseInterface
Parameters
- $channel : Channel
-
The channel to join.
- $mute : bool = false
-
Whether you should be mute when you join the channel.
- $deaf : bool = true
-
Whether you should be deaf when you join the channel.
- $logger : LoggerInterface|null = null
-
Voice client logger. If null, uses same logger as Discord client.
- $check : bool = true
-
Whether to check for system requirements.
Tags
Return values
PromiseInterface —listenCommand()
Add listerner for incoming application command from interaction.
public
listenCommand(string|array<string|int, mixed> $name[, callable $callback = null ][, callable|null $autocomplete_callback = null ]) : RegisteredCommand
Parameters
- $name : string|array<string|int, mixed>
- $callback : callable = null
- $autocomplete_callback : callable|null = null
Tags
Return values
RegisteredCommand —run()
Starts the ReactPHP event loop.
public
run() : void
Return values
void —updatePresence()
Updates the clients presence.
public
updatePresence([Activity|null $activity = null ][, bool $idle = false ][, string $status = 'online' ][, bool $afk = false ]) : void
Parameters
- $activity : Activity|null = null
-
The current client activity, or null. Note: The activity type cannot be custom, and the only valid fields are
name
,type
andurl
. - $idle : bool = false
-
Whether the client is idle.
- $status : string = 'online'
-
The current status of the client. Must be one of the following: online, dnd, idle, invisible, offline
- $afk : bool = false
-
Whether the client is AFK.
Tags
Return values
void —connectWs()
Initializes the connection with the Discord gateway.
protected
connectWs() : void
Return values
void —handleDispatch()
Handles dispatch events received by the WebSocket.
protected
handleDispatch(object $data) : void
Parameters
- $data : object
-
Packet data.
Return values
void —handleGuildMembersChunk()
Handles `GUILD_MEMBERS_CHUNK` packets.
protected
handleGuildMembersChunk(object $data) : void
Parameters
- $data : object
-
Packet data.
Tags
Return values
void —handleHeartbeat()
Handles heartbeat packets received by the client.
protected
handleHeartbeat(object $data) : void
Parameters
- $data : object
-
Packet data.
Return values
void —handleHeartbeatAck()
Handles heartbeat ACK packets received by the client.
protected
handleHeartbeatAck(object $data) : void
Parameters
- $data : object
-
Packet data.
Return values
void —handleHello()
Handles HELLO packets received by the websocket.
protected
handleHello(object $data) : void
Parameters
- $data : object
-
Packet data.
Return values
void —handleInvalidSession()
Handles invalid session packets received by the client.
protected
handleInvalidSession(object $data) : void
Parameters
- $data : object
-
Packet data.
Return values
void —handleReady()
Handles `READY` packets.
protected
handleReady(object $data) : false|void
Parameters
- $data : object
-
Packet data.
Tags
Return values
false|void —handleReconnect()
Handles reconnect packets received by the client.
protected
handleReconnect(object $data) : void
Parameters
- $data : object
-
Packet data.
Return values
void —handleResume()
Handles `RESUME` packets.
protected
handleResume(object $data) : void
Parameters
- $data : object
-
Packet data.
Return values
void —handleVoiceServerUpdate()
Handles `VOICE_SERVER_UPDATE` packets.
protected
handleVoiceServerUpdate(object $data) : void
Parameters
- $data : object
-
Packet data.
Return values
void —handleVoiceStateUpdate()
Handles `VOICE_STATE_UPDATE` packets.
protected
handleVoiceStateUpdate(object $data) : void
Parameters
- $data : object
-
Packet data.
Return values
void —identify()
Identifies with the Discord gateway with `IDENTIFY` or `RESUME` packets.
protected
identify([bool $resume = true ]) : bool
Parameters
- $resume : bool = true
-
Whether resume should be enabled.
Return values
bool —processWsMessage()
Process WebSocket message payloads.
protected
processWsMessage(string $data) : void
Parameters
- $data : string
-
Message payload.
Return values
void —ready()
Emits init if it has not been emitted already.
protected
ready() : false|void
Return values
false|void —resolveOptions()
Resolves the options.
protected
resolveOptions([array<string|int, mixed> $options = [] ]) : array<string|int, mixed>
Parameters
- $options : array<string|int, mixed> = []
-
Array of options.
Tags
Return values
array<string|int, mixed> —Options.
send()
Sends a packet to the Discord gateway.
protected
send(array<string|int, mixed> $data[, bool $force = false ]) : void
Parameters
- $data : array<string|int, mixed>
-
Packet data.
- $force : bool = false
Return values
void —setGateway()
Retrieves and sets the gateway URL for the client.
protected
setGateway([string|null $gateway = null ]) : ExtendedPromiseInterface
Parameters
- $gateway : string|null = null
-
Gateway URL to set.
Return values
ExtendedPromiseInterface —setupChunking()
Sets guild member chunking up.
protected
setupChunking() : false|void
Return values
false|void —setupHeartbeat()
Sets the heartbeat timer up.
protected
setupHeartbeat(int $interval) : void
Parameters
- $interval : int
-
The heartbeat interval in milliseconds.