Download the PHP package plytas/laravel-discord-interactions without Composer

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

Laravel (PHP) client that uses Discord HTTP API to create and respond to interactions

Latest Version on Packagist GitHub Tests Action Status GitHub Code Style Action Status Total Downloads

Create rich Discord interactions and respond to them using Laravel. Utilizes Discord HTTP webhooks without the need of a long-running process.

Installation

You can install the package via composer:

You can publish the config file with:

This is the contents of the published config file:

Configuration

Create a new discord application at https://discord.com/developers/applications. Copy the application id and public key from "General information" tab and bot token from "Bot" tab to your .env file.

Interactions endpoint setup

For local development you can use services such as expose or ngrok to expose your local server to the internet.

In your discord application fill in Interactions Endpoint URL under "General information" with the url of your server followed by the path you set in the config file. By default it is /discord.

When clicking the "Save Changes" button, Discord will send a couple POST request to the provided URL to verify the endpoint. One of them will intentionally contain an invalid signature. The package will automatically respond to these requests appropriately.

If the changes are saved successfully, you are good to go!

Usage

Creating a command

To create a new chat command, create a new class that implements the Plytas\Discord\Contracts\DiscordCommand interface.

Registering a command

You can register commands using Plytas\Discord\DiscordCommandRegistry::setCommands method. This can be done in the boot() method of a service provider.

And finally call php artisan discord:register-commands to register the commands with Discord. It's recommended to run this command in a deployment script.

Responding to interactions

Your commands will receive a DiscordInteraction object that contains information about the interaction. You can respond to the interaction directly by returning a DiscordResponse object. DidcordInteraction object contains helper methods to create responses such as respondWithMessage(), updateMessage() and showModal().

You must respond to interactions within 3 seconds. If you fail to do so, Discord will show a generic error message to the user. If you need more time to process the interaction, it is recommended to respond with a message that indicates that the command is still processing. After processing is done, you can use \Plytas\Discord\Facades\Discord::updateInteractionMessage() in a \Illuminate\Support\Facades\App::terminating() callback to update the message.

Responding to component interactions

You can add components to your messages to allow users to interact with them.

You can respond to component interactions by creating a new class that implements the \Plytas\Discord\Contracts\DiscordComponentHandler interface.

Registering component handlers

You can register component handlers using Plytas\Discord\DiscordComponentRegistry::setComponentHandlers() method. This method accepts an array of component_id => DiscordComponentHandler class. This can be done in the boot() method of a service provider.

If you need more control over the component handler registration process, you can use Plytas\Discord\DiscordComponentRegistry::handleComponentsUsing() method. This method accepts a closure that receives Plytas\Discord\Data\DiscordInteraction object and expects a Plytas\Discord\Data\DiscordResponse object to be returned.

Imagine that your components have a dynamic custom id that contains the name of the game. You can use the following code to handle the components:

[!WARNING] Not all components and API features are supported yet. This package started as a personal project and is still in development. If you need a specific feature, feel free to open an issue or a pull request.

Testing

Changelog

Please see CHANGELOG for more information on what has changed recently.

Contributing

Please see CONTRIBUTING for details.

Security Vulnerabilities

Please review our security policy on how to report security vulnerabilities.

Credits

License

The MIT License (MIT). Please see License File for more information.


All versions of laravel-discord-interactions with dependencies

PHP Build Version
Package Version
Requires php Version ^8.2
illuminate/contracts Version ^10.0||^11.0||^12.0
spatie/laravel-data Version ^4.6
spatie/laravel-package-tools Version ^1.16
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 plytas/laravel-discord-interactions contains the following files

Loading the files please wait ....