revolution/discord-manager

Discord Manager

5.1.1 2024-03-19 06:39 UTC

README

packagist Maintainability Test Coverage

Note Since v5, only Interactions command is provided. Interactions command is webhook-based, it is easy to use in Laravel. v4 still support Gateway API.

Requirements

  • PHP >= 8.1
  • Laravel >= 10.0

Installation

composer require revolution/discord-manager

.env

DISCORD_BOT_TOKEN=

# APPLICATION ID
DISCORD_BOT=

# PUBLIC KEY
DISCORD_PUBLIC_KEY=

# GUILD ID
DISCORD_GUILD=

Uninstall

composer remove revolution/discord-manager
  • Delete config/discord_interactions.php
  • Delete app/Discord/ and other files.
  • Delete DISCORD_* in .env

Interactions

Publish config file

php artisan vendor:publish --tag=discord-interactions-config

Edit config/discord_interactions.php

Set INTERACTIONS ENDPOINT URL in Discord's developer portal.

https://example/discord/webhook

Create a command to respond

php artisan discord:make:interaction HelloCommand

Register commands to Discord server

php artisan discord:interactions:register

Create Event listener

php artisan make:listener InteractionsListener
use Revolution\DiscordManager\Events\InteractionsWebhook;
use Revolution\DiscordManager\Facades\DiscordManager;

//

    /**
     * Handle the event.
     *
     * @param  InteractionsWebhook  $event
     * @return void
     */
    public function handle(InteractionsWebhook $event)
    {
        DiscordManager::interaction($event->request);
    }

(Only Laravel10) Update EventServiceProvider.php

use App\Listeners\InteractionsListener;
use Revolution\DiscordManager\Events\InteractionsWebhook;

//

    protected $listen = [
        Registered::class => [
            SendEmailVerificationNotification::class,
        ],
        InteractionsWebhook::class => [
            InteractionsListener::class,
        ],
    ];

Workflow

  1. POST request comes in from Discord to https://example/discord/webhook
  2. ValidateSignature
  3. InteractionsWebhookController
  4. DeferredResponse
  5. DispatchInteractionsEvent Terminable Middleware
  6. InteractionsWebhook Event dispatch
  7. InteractionsListener in your project.
  8. DiscordManager invokes one of the commands in app/Discord/.

LICENSE

MIT