Download the PHP package dainc007/laravel-discord-server without Composer

On this page you can find all versions of the php package dainc007/laravel-discord-server. 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 laravel-discord-server

laravel-discord-server

Tests Latest version PHP version

Manage a Discord server from Laravel with a bot token: give and take roles, set nicknames, time out, kick and ban members, create and edit roles and channels. Every change shows up in Discord's own audit log with who made it and why, and is written to a change log table, also when Discord refuses it. Built on dainc007/discord-rest-client.

Install

Then add to .env:

Requires PHP 8.3+ and Laravel 12 or 13. To change the defaults, publish the config: php artisan vendor:publish --tag="discord-server-config".

Creating the bot, inviting it with the right permissions and finding the server id are described in the client's setup guide. The step that trips most people: the bot's role must sit above every role it should give or edit.

Check the setup

It reads the server with your token and reports: whether the bot reaches it, which permissions this package uses are missing, and which roles sit at or above the bot's highest role (the bot cannot give or edit those). It changes nothing. The bot's user id is read from the token; pass --bot-id= if that fails. It exits with an error when the server cannot be read or a --role is out of the bot's reach, so it also works in a deploy script.

Usage

Discord's audit log then shows "My App: Anna: Linked Discord account" (the prefix is APP_NAME), and a row lands in discord_changes.

actingAs(), because() and forGuild() each return a copy, so a configured instance can be kept:

Members Roles Channels
addRole, removeRole, syncRoles, setNickname, timeout, kick, ban, unban createRole, editRole, deleteRole createChannel, editChannel, deleteChannel

Reads go straight to the client and skip the change log:

Keeping roles in step with your app

syncRoles() gives a member every role in wanted, and takes away each role listed in managed but missing from wanted. Roles outside both lists, such as ones a moderator gave by hand, stay.

Your app decides who gets which role and which Discord account belongs to which user, and passes both in.

Your own changes

For a write without its own method (reordering, permission overwrites), wrap it in record() to get the audit reason and the log entry:

To keep working with the log row the change wrote (show it, link to it, add to it), use recordChange(). It returns the change's result and that exact row, even when other changes are logged at the same moment:

Who made the change

Any Eloquent model can be the actor. Discord's audit log shows its name attribute. To choose another name, implement NamedDiscordActor:

Call Discord from a queued job

A call can take a while: up to 10 seconds per try, a few retries, and a wait when Discord's rate limit says so (up to 60 seconds by default). Inside a web request, that is a page that hangs. Make changes from a queued job:

If a call must run during a request, publish the config and lower max_retries and max_retry_after_seconds, so a busy Discord fails fast.

When Discord says no

A refused change is logged with succeeded = false, Discord's HTTP status, its error code and message. Then the client's exception is thrown again unchanged, so your app decides what to show: MissingPermissionException (403, often the role order), UnknownResourceException (404), RateLimitedException, InvalidTokenException, TransportException (network). All extend DiscordException. See the client's error list.

A missing token or server id throws DiscordServerNotConfigured before any request.

The change log

Every logged change fires Dainc007\LaravelDiscordServer\Events\DiscordChangeRecorded, also when Discord refused it ($event->change->succeeded tells which), so an app can notify someone or react. This event is the only way to reach the row of a refused change: recordChange() throws Discord's exception instead of returning. An error thrown by a listener is reported (report()) and does not stop the change or replace Discord's error:

Dainc007\LaravelDiscordServer\Models\DiscordChange, one row per change:

Column
actor_type, actor_id who (actor() relation), null for the console or a job
guild_id, action where and what, e.g. member.add_role
target_type, target_id, target_name the member, role or channel
details JSON: role id, nickname, the reason, ...
succeeded, http_status, discord_code, error the outcome

Turn it off with change_log.enabled = false, or rename the table with change_log.table before migrating.

Entries older than change_log.keep_days (90 by default; null keeps everything) are deleted by Laravel's model:prune. The model lives outside app/Models, so name it when you schedule the command:

Rate limits

Discord's rate-limit buckets are kept in the Laravel cache, so web requests and queue workers know about each other's limits. This is best effort: two workers can read "one request left" at the same moment, and one of them then gets a 429, waits and retries. Set DISCORD_RATE_LIMIT_STORE to pick a store; the array store keeps them per process. The client's rate-limit notes still apply: the 50-requests-a-second count is per process.

The client is bound as a scoped service, so under Octane each request gets its own.

Testing your app

The fake makes no HTTP calls and the change log keeps working. When no server id is configured, the fake fills one in. Queue a DiscordException to test a refusal. The fake stays in place when Laravel resets per-request services, as a queue worker does between jobs.

Planned

A queued version of the change methods. A Filament plugin with pages for roles, channels, members and the change log comes as a separate package.

Package tests

Changelog and security

See SECURITY.md.

Licence

MIT. See LICENSE.md.


All versions of laravel-discord-server with dependencies

PHP Build Version
Package Version
Requires php Version ^8.3
dainc007/discord-rest-client Version ^0.1
guzzlehttp/guzzle Version ^7.8
illuminate/cache Version ^12.0 || ^13.0
illuminate/contracts Version ^12.0 || ^13.0
illuminate/database Version ^12.0 || ^13.0
illuminate/support Version ^12.0 || ^13.0
spatie/laravel-package-tools Version ^1.92
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 dainc007/laravel-discord-server contains the following files

Loading the files please wait ...