GatewayDiagnostics
in package
Turns a Discord gateway close code into something you can act on.
DiscordPHP logs not reconnecting - critical op code and puts the code in
the record's context, which a log line that prints only the message throws
away. What is left says the bot stopped and nothing about why — and the two
most common causes have completely different fixes that look identical from
the outside: the bot connects, identifies, and is dropped a second later.
Every string here names the specific thing to change, because "authentication failed" sends people to re-copy a token that was never the problem.
Tags
Table of Contents
Constants
- FATAL : mixed = [4004, 4010, 4011, 4012, 4013, 4014]
- Codes DiscordPHP refuses to reconnect after — the ones worth explaining.
Methods
- explain() : string|null
- A plain-English explanation and fix, or `null` for a code with no better advice than the reason Discord already gave.
- fromLogContext() : int|null
- Pulls the close code out of a log record's context.
- isFatal() : bool
- Whether a close code is one the client will not recover from on its own.
- report() : string
- The whole message to print for a fatal close, including the raw code and Discord's own reason — which is worth keeping even when the explanation above is better, since it is what a search engine will match.
Constants
FATAL
Codes DiscordPHP refuses to reconnect after — the ones worth explaining.
public
mixed
FATAL
= [4004, 4010, 4011, 4012, 4013, 4014]
Methods
explain()
A plain-English explanation and fix, or `null` for a code with no better advice than the reason Discord already gave.
public
static explain(int $op[, string $reason = '' ]) : string|null
Parameters
- $op : int
- $reason : string = ''
Return values
string|nullfromLogContext()
Pulls the close code out of a log record's context.
public
static fromLogContext(string $message, array<string, mixed> $context) : int|null
DiscordPHP is the only thing that knows the code, and it only ever
reports it by logging — there is no event to listen for — so reading it
back off the record is the one hook available without patching the
library. Returns null for anything that is not a fatal gateway close,
which is every other record the logger will ever see.
Parameters
- $message : string
- $context : array<string, mixed>
Return values
int|nullisFatal()
Whether a close code is one the client will not recover from on its own.
public
static isFatal(int $op) : bool
Parameters
- $op : int
Return values
boolreport()
The whole message to print for a fatal close, including the raw code and Discord's own reason — which is worth keeping even when the explanation above is better, since it is what a search engine will match.
public
static report(int $op[, string $reason = '' ]) : string
Parameters
- $op : int
- $reason : string = ''