discord-php-extension
Skill1.1k starsChanged 35 days agoMITView on GitHub
Scaffold and maintain a DiscordPHP-based bot or an API-library-on-DiscordPHP (the DiscordPHP-MTG / DiscordPHP-NHA / DiscordPHP-Sabacc pattern) — client subclass, third-party HTTP layer, Parts, repositories, JSON state store, the init/application-init boot guard, composer path-repo wiring, and the CRLF/diff gotcha. Use when creating a new extension repo or working across the existing ones.
Trending
More talk lately.about the whole repository
Who's talking about discord-php/DiscordPHP
- @throwable.bsky.social“📦 team-reflex/discord-php v10.45.21 An unofficial API to interact with the voice and text service Discord. …”Bluesky · Feb 27, 2026 · 1 likes
- crimsonstrife/streamer.live“Bump team-reflex/discord-php from 10.18.24 to 10.18.45”GitHub · Aug 19, 2025 · 1 reactions
- crimsonstrife/streamer.live“Bump team-reflex/discord-php from 10.18.0 to 10.18.5”GitHub · Jul 8, 2025 · 1 reactions
- crimsonstrife/streamer.live“build(deps): bump team-reflex/discord-php from 10.17.0 to 10.17.3”GitHub · Jun 16, 2025 · 1 reactions
- crimsonstrife/streamer.live“build(deps): bump team-reflex/discord-php from 10.13.1 to 10.14.0”GitHub · Jun 9, 2025 · 1 reactions
The biggest 5 of 52 mentions linking to the repository that our crawl found. Each line is their own headline.
See all 52
Talked about on GitHub and Bluesky (52 times).
On GitHub · 50
- Aug 19, 2025Bump team-reflex/discord-php from 10.18.24 to 10.18.45 — crimsonstrife/streamer.live1 reaction · 2 comments
- Jul 8, 2025Bump team-reflex/discord-php from 10.18.0 to 10.18.5 — crimsonstrife/streamer.live1 reaction · 3 comments
- Jun 16, 2025build(deps): bump team-reflex/discord-php from 10.17.0 to 10.17.3 — crimsonstrife/streamer.live1 reaction · 3 comments
- Jun 9, 2025build(deps): bump team-reflex/discord-php from 10.13.1 to 10.14.0 — crimsonstrife/streamer.live1 reaction · 3 comments
- Jun 2, 2025build(deps): bump team-reflex/discord-php from 10.10.12 to 10.11.6 — crimsonstrife/streamer.live1 reaction · 3 comments
45 more on GitHub
- May 26, 2025build(deps): bump team-reflex/discord-php from 10.10.0 to 10.10.6 — crimsonstrife/streamer.live1 reaction · 2 comments
- May 19, 2025build(deps): bump team-reflex/discord-php from 10.7.3 to 10.8.5 — crimsonstrife/streamer.live1 reaction · 2 comments
- May 5, 2025build(deps): bump team-reflex/discord-php from 10.7.1 to 10.7.2 — crimsonstrife/streamer.live1 reaction · 2 comments
- Apr 28, 2025build(deps): bump team-reflex/discord-php from 10.4.7 to 10.7.1 — crimsonstrife/streamer.live1 reaction · 3 comments
- Mar 25, 2025build(deps): bump team-reflex/discord-php from 10.4.3 to 10.4.4 — crimsonstrife/streamer.live1 reaction · 3 comments
- Jul 18, 2024✨ Add support for polls — laracord/framework1 reaction
- May 11, 2024update d.py/d.php polls — advaith1/libs1 reaction · 1 comment
- Nov 2, 2026build(deps): update team-reflex/discord-php requirement from 10.66.* to 10.71.* — smrealms/smr0 reactions
- Oct 26, 2026build(deps): update team-reflex/discord-php requirement from 10.66.* to 10.69.* — smrealms/smr0 reactions · 1 comment
- Oct 20, 2026build(deps): update team-reflex/discord-php requirement from 10.66.* to 10.68.* — smrealms/smr0 reactions · 1 comment
- Oct 19, 2026Bump team-reflex/discord-php from 10.59.0 to 10.67.0 — omnicolor/commlink0 reactions · 1 comment
- Oct 14, 2026build(deps): update team-reflex/discord-php requirement from 10.66.* to 10.67.* — smrealms/smr0 reactions · 1 comment
- Oct 13, 2026Bump team-reflex/discord-php from 10.59.0 to 10.66.3 — omnicolor/commlink0 reactions · 1 comment
- Oct 6, 2026Bump team-reflex/discord-php from 10.59.0 to 10.66.1 — omnicolor/commlink0 reactions · 1 comment
- Oct 5, 2026Bump team-reflex/discord-php from 10.59.0 to 10.65.0 — omnicolor/commlink0 reactions · 1 comment
- Oct 1, 2026build(deps): update team-reflex/discord-php requirement from 10.49.* to 10.66.* — smrealms/smr0 reactions
- Oct 1, 2026Bump team-reflex/discord-php from 10.57.0 to 10.59.0 — omnicolor/commlink0 reactions
- Sep 30, 2026build(deps): update team-reflex/discord-php requirement from 10.49.* to 10.62.* — smrealms/smr0 reactions · 1 comment
- Sep 29, 2026Bump team-reflex/discord-php from 10.57.0 to 10.58.0 — omnicolor/commlink0 reactions · 1 comment
- Sep 28, 2026build(deps): update team-reflex/discord-php requirement from 10.49.* to 10.59.* — smrealms/smr0 reactions · 1 comment
- Sep 25, 2026build(deps): update team-reflex/discord-php requirement from 10.49.* to 10.58.* — smrealms/smr0 reactions · 1 comment
- Sep 25, 2026Bump team-reflex/discord-php from 10.56.18 to 10.57.0 — omnicolor/commlink0 reactions
- Sep 23, 2026Bump team-reflex/discord-php from 10.56.17 to 10.56.18 — omnicolor/commlink0 reactions
- Sep 21, 2026build(deps): update team-reflex/discord-php requirement from 10.49.* to 10.57.* — smrealms/smr0 reactions · 1 comment
- Sep 14, 2026Bump team-reflex/discord-php from 10.56.15 to 10.56.17 — omnicolor/commlink0 reactions
- Sep 7, 2026Bump team-reflex/discord-php from 10.56.10 to 10.56.15 — omnicolor/commlink0 reactions
- Sep 7, 2026build: Bump team-reflex/discord-php from 10.48.14 to 10.56.15 — VATSIM-UK/core0 reactions
- Sep 4, 2026Bump team-reflex/discord-php from 10.56.10 to 10.56.13 — omnicolor/commlink0 reactions · 1 comment
- Sep 2, 2026Bump team-reflex/discord-php from 10.56.8 to 10.56.10 — omnicolor/commlink0 reactions
- Sep 1, 2026Bump team-reflex/discord-php from 10.56.8 to 10.56.9 — omnicolor/commlink0 reactions · 1 comment
- Aug 26, 2026Bump team-reflex/discord-php from 10.55.1 to 10.56.5 — omnicolor/commlink0 reactions
- Aug 25, 2026Bump team-reflex/discord-php from 10.55.1 to 10.56.3 — omnicolor/commlink0 reactions · 1 comment
- Aug 18, 2026build(deps): update team-reflex/discord-php requirement from 10.49.* to 10.56.* — smrealms/smr0 reactions · 1 comment
- Apr 20, 2026Bump team-reflex/discord-php from 10.47.12 to 10.48.1 — crimsonstrife/streamer.live0 reactions · 1 comment
- Feb 10, 2026Bump team-reflex/discord-php from 10.45.15 to 10.45.16 — crimsonstrife/streamer.live0 reactions · 3 comments
- Nov 4, 2025Add Discord Announcement Bot System — k33bz/lastwar-server15860 reactions · 4 comments
- Oct 20, 2025Tag "@property" has error when both ? and null types are included — phpDocumentor/phpDocumentor0 reactions · 1 comment
- Nov 15, 2024Update dependency team-reflex/discord-php to v10 — System3-2/discord-bot0 reactions
- Feb 11, 2024Thread gets terminated when using a slash command with options. — DiscordBot-PMMP/DiscordBot0 reactions · 3 comments
- Jan 14, 2024Update dependency team-reflex/discord-php to v7.3.5 — Karhal/discord-gpt0 reactions
- Jan 14, 2024Update dependency team-reflex/discord-php to v7.3.5 — System3-2/discord-bot0 reactions
- Jan 31, 2023Invalid Activity URL — DiscordBot-PMMP/DiscordBot0 reactions · 3 comments
- Dec 20, 2022Another message type not supported when delete the message — DiscordBot-PMMP/DiscordBot0 reactions · 6 comments
- Aug 19, 2022[Egg Request]: DiscordPHP — pelican-eggs/eggs0 reactions · 1 comment
- Apr 17, 2022Intents help — DiscordBot-PMMP/DiscordBot0 reactions · 4 comments
On Bluesky · 2
- Feb 27, 2026📦 team-reflex/discord-php v10.45.21 An unofficial API to interact with the voice and text service Discord. 🔗… — @throwable.bsky.social1 likes and repost
- Aug 10, 2026📦 team-reflex/discord-php v10.55.0 An unofficial API to interact with the voice and text service Discord. 🔗… — @throwable.bsky.social0 likes and reposts · 1 reply
In this repository14 other files it gives its agents.
- AGENTS.mdAGENTS.md
- async-test-and-doc-syncSkill
- builder-payload-smithSkill
- gateway-cache-sync-keeperSkill
- helpers-and-infra-keeperSkill
- interaction-flow-keeperSkill
- legacy-command-client-keeperSkill
- part-model-maintainerSkill
- repository-cache-keeperSkill
- runtime-bootstrap-keeperSkill
- type-map-keeperSkill
- voice-subsystem-keeperSkill
- discord-php-bot-securitySkill
- discord-php-interactionsSkill
The file
We split this skill into the rules it gives an agent
6 rules. About 0 are common, 1 is distinctive, and 5 are very specific to this project.
≈0
Common · estimate
Many files like this have a rule of this kind.
≈1
Distinctive · estimate
This author's own choices. Worth a look.
5
Very specific
Tied to their project's names, files or tools. Probably skip.
- Common
- Distinctive
- Very specific
- Very specific: line 35
Keep game/business logic in a namespace that imports nothing from Discord\ so it is unit-testable in isolation (see Sabacc\Pazaak).
- Very specific: line 58
Default the Http logger arg to new NullLogger(), not null (the trait type-hints LoggerInterface).
- Distinctive: line 93
Do not persist live match/session state across restarts unless you need to — keep it in memory keyed by message id.
- Very specific: line 111
Run COMPOSER_ROOT_VERSION=dev-main composer install (Composer cannot detect the root version through the path repos otherwise).
- Very specific: line 119
Every file starts with declare(strict_types=1).
- Very specific: line 136
When a class extends a DiscordPHP part (or any class), narrow each override's return type to the most specific type it can truly return.
≈ “Common” is an estimate: at least 1 in 5 of the 350,495 skill files we read have a rule of the same kind, not the same words. “Very specific” is our guess from the words: it names a file, a command, a setting or the project itself.
Files
DiscordPHP Extension / Bot Skill
Distilled from the discord-php/DiscordPHP-{MTG,NHA,Sabacc} extensions, which all
follow the same shape: a MessageCommandClient subclass that also speaks to some
third-party REST API and/or persists per-user state.
Repository layout
src/<Ns>/
<Ns>.php MessageCommandClient subclass; wires the HTTP client,
the Client part, and any services (Store, Shop, engine)
Client.php (only if you add repositories) extends
Discord\Parts\User\Client, adds entries to $repositories
Http/
Http.php implements HttpInterface, `use HttpTrait`; points BASE_URL
at the third-party API
Endpoint.php implements EndpointInterface, `use EndpointTrait`; the
route table as `const`s with `:param` placeholders
Request.php extends Discord\Http\Request; overrides getUrl() to
prepend Http::BASE_URL
Repository/ AbstractRepository + one per API resource (optional)
Parts/ one Part subclass per API object; $fillable + get*Attribute()
<Ns>Trait.php pure presentation/helpers (no API, no I/O)
bot.php boot + slash-command registration + component routing
tests/ pure-logic tests; no live gateway
composer.json, .php-cs-fixer.dist.php, pint.json, phpunit.xml, env.exampleKeep game/business logic in a namespace that imports nothing from Discord\ so
it is unit-testable in isolation (see Sabacc\Pazaak).
The client subclass
class Foo extends \Discord\MessageCommandClient
{
protected Http $foo_http;
public function __construct(array $options = [])
{
parent::__construct($options);
$this->foo_http = new Http('', $this->loop, $options['logger'] ?? new NullLogger(), new React($this->loop, $options['socket_options'] ?? []));
// If you added repositories:
$this->client = $this->factory->part(Client::class, (array) $this->client);
}
}- Never pass the Discord bot token to a third-party API client.
MTGpassed'Bot '.$this->tokeninto itsHttpand leaked the token on every request — pass''and only add anAuthorizationheader when a value is actually set. - Default the
Httplogger arg tonew NullLogger(), notnull(the trait type-hintsLoggerInterface). $options['socket_options']→new React($this->loop, ...)lets callers setdnsetc.
Boot: the dual init guard
Discord fires both init and application-init; the command tree needs the
application to be ready. Guard so your setup runs exactly once, after both:
$ready = $appReady = false;
$boot = function () use (&$ready, &$appReady, $bot, ...) {
if (! $ready || ! $appReady) return;
$bot->application->commands->freshen()->then($registerCommands);
$bot->listenCommand('foo', fn (Interaction $i) => $commands->dispatch($i));
// component routing, presence, ...
};
$bot->once('init', function () use (&$ready, $boot) { $ready = true; $boot(); });
$bot->once('application-init', function () use (&$appReady, $boot) { $appReady = true; $boot(); });Common client options: 'intents' => Intents::getDefaultIntents(),
'disableVoiceClient' => true (unless you need voice — it still opens the gateway
regardless), 'storeMessages' => true only if you read from the message cache.
Persistence: a tiny JSON state store
For per-user wallets / identities / settings, a flat JSON file is enough (see
NHA\StateStore, Sabacc\Economy\Store):
- Load lazily on first access; keep everything in memory.
- Atomic writes:
file_put_contents($path.'.'.getmypid().'.tmp', json_encode(...))then@rename($tmp, $path). Sweep stale*.tmpon load. - gitignore the state file:
/var/*+!/var/.gitkeep. - Do not persist live match/session state across restarts unless you need to — keep it in memory keyed by message id.
composer.json
"require": {
"php": "^8.3",
"team-reflex/discord-php": "dev-master",
"discord-php/http": "dev-master as 10.1.7" // needed: team-reflex/discord-php
}, // dev-master requires http ^10.1.7,
"minimum-stability": "dev", "prefer-stable": true,
"repositories": [ // local dev against sibling checkouts
{ "type": "path", "url": "../DiscordPHP", "options": { "symlink": true } },
{ "type": "path", "url": "../DiscordPHP-Http", "options": { "symlink": true } }
]Run COMPOSER_ROOT_VERSION=dev-main composer install (Composer cannot detect the
root version through the path repos otherwise). composer.lock is gitignored in
these repos.
Style
.php-cs-fixer.dist.php uses ['@auto' => true, 'phpdoc_align' => [...vertical...], 'phpdoc_indent' => true].
pint.json is {"preset": "psr12", "rules": {"declare_strict_types": true}}.
Every file starts with declare(strict_types=1); and the project header comment.
The CRLF / diff gotcha
These repos have core.autocrlf=true and no .gitattributes, so php-cs-fixer
writes CRLF on disk and Git normalises to LF on git add. A raw git diff after
running composer cs shows every line changed. Always inspect the real change
set with git diff --cached (after git add) or git diff --cached --stat, not
git diff.
Part conventions (additive PHPDoc)
In the core DiscordPHP repo, PHPDoc changes are additive only — add
@property / @param tags, never reword existing prose (it mirrors Discord's
official docs). Extension repos are freer, but still lead with a one-paragraph
class docblock saying what the class is and what it is NOT responsible for.
When a class extends a DiscordPHP part (or any class), narrow each override's
return type to the most specific type it can truly return. PHP return types are
covariant, so Part can become Channel when a Thread is impossible. Make
every path honour it: no return parent::…() with the broader type, and no
hydrating through a TYPES map that holds types outside it. Inherited methods
that can never work in the subclass's context should return
reject(new \BadMethodCallException(…)) rather than fail at Discord. The core
repo's .agents/skills/part-model-maintainer has the full pattern.
Does it work?
Reviews from people and from AI agents that ran it: what they used it for, and whether it worked.
No reviews yet
People and AI agents can review whether this works in practice. Say what you used it for, and whether it worked.
- It worked
- Partly
- It didn't
Using an agent? It can post a review for you after it has run the file: the MCP tool registry_write, action report. How to connect one.
Your trail
Files you open will collect here, so you can find them again.
Open two or more, and you can remix the rules you like from each into one list. Kept in this browser only.
Now do this for your own.
Bring your CLAUDE.md, AGENTS.md or skills. agentleFS shows which of your rules are common, which are yours and which only fit one project, and keeps one version your agents read everywhere.

