Download the PHP package thediscordlist/integration-discordphp without Composer

On this page you can find all versions of the php package thediscordlist/integration-discordphp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package integration-discordphp

thediscordlist/integration-discordphp

Publish your DiscordPHP bot's server count, shard heartbeats and application commands to TheDiscordList automatically, and verify its inbound webhooks.

No runtime dependencies of its own: the autoposter runs on the ReactPHP loop and react/http client DiscordPHP already ships with, and the webhook verifier needs nothing but PHP.

Quickstart

That is the whole integration, and it is also the recommended production setup. It starts three publishers:

Publisher What it sends Cadence
Stats server_count, shard_count 5s after init, then every 5 min, debounced 20s on guild join/leave
Heartbeat this shard's status, gateway latency and guild count every 30–35s, plus once after a gateway error or reconnect (at least 10s after the previous beat)
Commands your global application commands once, 10s after init, retried every 5 min after a server error, a rate limit or a failed fetch from Discord

Your stats token is on the listing's manage page, under the API tab. It is scoped to one listing, so it is the only credential this package needs.

attach() is safe before or after $discord->run(), including from inside an init handler. Every request goes through react/http on DiscordPHP's own loop, so nothing ever blocks the gateway. With a missing token it logs one warning and returns an inert instance: a forgotten environment variable never takes down a deploy.

Sharding

DiscordPHP opens one gateway connection per Discord instance, so a sharded bot runs one instance per shard, usually one per process. Each instance is its own cluster with exactly one shard, read from the same options DiscordPHP identifies with (shard, shard_id + num_shards, or shardId + shardCount):

Layout server_count comes from Stats and commands posted by Heartbeats
Single instance, no shard options $discord->guilds->count() this instance cluster 0 of 1
One instance per shard your serverCount callback shard 0 every shard, as cluster shard id of shard count
Anything else your serverCount callback cluster['id'] === 0 as configured by cluster

DiscordPHP has no cross-process bus, so a sharded bot has to say where the bot-wide total lives. Without serverCount, shard 0 disables its stats publisher with a clear log line rather than publishing one shard's guilds as the total:

For a layout the shard options do not describe, name the cluster yourself:

Every instance heartbeats for itself on purpose. A manager reporting "all fine" for a process whose host has died is exactly the failure the status page exists to catch.

If the cluster count cannot be determined, heartbeats do not start. The API hard-deletes every cluster row whose id is >= cluster_count in the request, so one process guessing 1 would erase all of its siblings and their monitoring history. A malformed shard option or a cluster override with a count of 0 (an unset environment variable) disables the heartbeat publisher with a disabled event naming the cluster option as the fix. Losing a status page beats losing data.

Options

Pass an array with these keys, or the same names as named arguments to new Options(...). Durations are seconds, like ReactPHP timers.

statsMinGap is a hard floor between two stats POSTs and is never below 60. A join storm, a mass reconnect and a manual postStats() all route through it, so the ceiling is structurally one request per minute.

postEmptyCommands is false because posting an empty list clears the command list on your listing. Turn it on only if that is what you mean.

With botId set, the heartbeat starts before the gateway connects, so a booting bot reads "connecting" on its status page instead of looking dead.

Events and manual posting

Autoposter is an Evenement emitter, like Discord itself:

Nothing in this package throws at your bot. Timer callbacks and event handlers are guarded, the postX() promises always resolve (never reject) with a PostResult, and an error with no listener is logged through DiscordPHP's logger instead. disabled is always logged, since it needs a human.

A PostResult with ok === false and a skipped reason (unchanged, min-gap, not-elected, suspended, plan, empty, …) means nothing was sent, which is usually correct rather than a failure.

An explicit postX() also re-arms a publisher that disabled itself, so you can retry after fixing a token or a listing id without restarting. stop() cancels every timer and detaches every listener; $discord->close() does the same.

Webhooks

The Webhooks namespace never needs DiscordPHP, and needs ReactPHP only when your callback returns a promise, so it works in any PHP application.

Verifying by hand

A blank $secret throws an InvalidArgumentException: nothing could ever verify against it.

$rawBody must be the exact bytes that arrived. TheDiscordList signs the JSON string it sends, so json_encode($request->all()) escapes slashes and unicode differently and can never verify: the signature covers bytes, not meaning.

Laravel

In routes/api.php, which has no CSRF middleware:

PSR-15 (Slim, Mezzio, ReactPHP, …)

WebhookHandler is a PSR-15 RequestHandlerInterface. It needs the interface-only packages psr/http-server-handler and psr/http-factory, plus any PSR-17 factory:

It answers 204 once your callback returns, for every event name, 401 for a missing or invalid signature, 400 for any other verification failure, 413 for a body over 1 MiB, 405 for anything but POST, and 500 when your callback throws so the delivery is retried. A blank secret throws at construction. It is also invokable, so new React\Http\HttpServer($loop, $handler) serves it on the bot's own loop.

Your callback may return a ReactPHP promise. Served by HttpServer, the handler waits up to 8 seconds for it (timeout:): 204 when it fulfils, 500 when it rejects, and 202 if it is still running, so the sender's 10-second timeout is never hit. A synchronous PSR-15 handle() cannot wait and answers 202 for any promise. A rejection always reaches onError. examples/bot.php shows the same with Verifier alone and no extra packages.

Events

Event Fires for data
listing.bumped servers, bots points, bumped_at, next_bump_at, user
listing.bump_ready servers, bots ready_at
listing.upvoted servers, bots voted_at, total_upvotes, user
server.joined servers only joined_at, user
bot.added bots added_at, user
bot.stats_reported bots guild_count, shard_count, reported_at
webhook.ping both message

Every payload carries id, event, created_at, listing (id, type, name, url) and data. user is null or id, username, avatar.

Two of them are not what their names suggest. bot.added is a click event, dispatched on the install hand-off; Discord never tells anyone whether the install completed. And bot.stats_reported is not an echo of your own POST: it also fires when the owner edits the listing in the web UI, and on the heartbeat's stats forward. created_at is enqueue time, not send time, so never use it for freshness.

Rules for a healthy endpoint

Plans, limits and known behaviour

Requirements

Working on this repository needs PHP >= 8.2 (PHPUnit 11). CI tests 8.2, 8.3 and 8.4 and lints the sources on 8.1.

Publishing (maintainers)

Packagist builds releases from git tags; there is no upload step and no registry token in this repository.

One-time setup:

  1. Sign in to packagist.org with the GitHub account that administers TheDiscordList/integration-discordphp, preferably as a member of a thediscordlist Packagist maintainer group.
  2. Submit https://github.com/TheDiscordList/integration-discordphp. The package name comes from composer.json.
  3. Under your Packagist profile, connect GitHub (or install the Packagist GitHub app for the organisation) so the repository gets the Packagist hook and every push and tag updates the package automatically. The package page shows a warning while it is not auto-updated.

Each release:

  1. Move the Unreleased notes in CHANGELOG.md under the new version and bump Autoposter::VERSION (it is sent in the User-Agent; a test keeps the two in step).
  2. Merge to main with CI green.
  3. git tag v0.2.1 && git push origin v0.2.1. The release workflow checks the tag against Autoposter::VERSION, runs the suite and creates the GitHub release; Packagist picks the tag up through the hook within a minute.

License

MIT


All versions of integration-discordphp with dependencies

PHP Build Version
Package Version
Requires php Version >=8.1
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package thediscordlist/integration-discordphp contains the following files

Loading the files please wait ...