Laracord

Create powerful Discord bots with the power of Laravel and DiscordPHP.

laracord
|

Everything You Need to Build Amazing Discord Bots

Laracord combines the power of Laravel with Discord's rich API to create an unparalleled development experience for bot creators.

Laravel Zero Powered

Built on Laravel Zero micro-framework with full access to Laravel features like Eloquent, caching, and services.

Plugin Ecosystem

Extensible plugin system allows for reusable components and a growing ecosystem of Discord bot functionality.

Auto-Discovery

Automatic discovery of commands, slash commands, events, and tasks from your app directories with zero configuration.

Command Middleware

Global and individual command middleware for rate limiting, authentication, and custom logic processing.

HTTP Server

Optional HTTP server with native Laravel routing and Livewire support for web dashboards and webhooks.

Interactive Console

Beautiful console with custom prompts, colorful logging, and real-time bot interaction during development.

Background Tasks

Generate asynchronous services and tasks that run parallel to your bot for scheduled operations.

Error Handling

Laravel-native exception handling with Collision for beautiful error rendering and comprehensive logging.

Where Laravel Patterns Power Discord Bots

Use Laravel's expressive syntax and familiar project structure to build Discord bots.

Commands

Traditional prefix commands with interactive components

PingCommand.php
<?php

namespace App\Commands;

use Discord\Builders\Components\Button;
use Discord\Parts\Channel\Message;
use Discord\Parts\Interactions\Interaction;
use Laracord\Commands\Command;

class PingCommand extends Command
{
    /**
     * The command name.
     *
     * @var string
     */
    protected $name = 'ping';

    /**
     * The command description.
     *
     * @var string
     */
    protected $description = 'Ping? Pong!';

    /**
     * Handle the command.
     */
    public function handle(Message $message, array $args): void
    {
        $this
            ->message('Ping? Pong!')
            ->title('Ping')
            ->field('Response time', $message->timestamp->diffForHumans(null, true))
            ->button('Laracord Resources', route: 'resources', emoji: '💻', style: Button::STYLE_SECONDARY)
            ->reply($message);
    }

    /**
     * The command interaction routes.
     */
    public function interactions(): array
    {
        return [
            'resources' => fn (Interaction $interaction) => $this
                ->message('Check out the resources below to learn more about Laracord.')
                ->title('Laracord Resources')
                ->buttons([
                    'Documentation' => 'https://laracord.com',
                    'GitHub' => 'https://github.com/laracord/laracord',
                ])
                ->reply($interaction, ephemeral: true),
        ];
    }
}

Slash Commands

Auto-syncing slash commands with full Discord API support

HelloSlashCommand.php
<?php

namespace App\SlashCommands;

use Discord\Parts\Interactions\Interaction;
use Laracord\Commands\SlashCommand;

class HelloSlashCommand extends SlashCommand
{
    /**
     * The command name.
     *
     * @var string
     */
    protected $name = 'hello';

    /**
     * The command description.
     *
     * @var string
     */
    protected $description = 'A simple hello command.';

    /**
     * The command options.
     *
     * @var array
     */
    protected $options = [];

    /**
     * Handle the command.
     */
    public function handle(Interaction $interaction): void
    {
        $this
            ->message('Hello world!')
            ->button('👋', route: 'wave')
            ->reply($interaction, ephemeral: true);
    }

    /**
     * The command interaction routes.
     */
    public function interactions(): array
    {
        return [
            'wave' => fn (Interaction $interaction) => $this->message('👋')->reply($interaction, ephemeral: true),
        ];
    }
}

Event Listeners

React to Discord events with elegant Laravel event listeners

MessageListener.php
<?php

namespace App\Events;

use Discord\Discord;
use Discord\Parts\Channel\Message;
use Discord\WebSockets\Event as Events;
use Illuminate\Support\Str;
use Laracord\Events\Event;

class MessageListener extends Event
{
    /**
     * The event handler.
     *
     * @var string
     */
    protected $handler = Events::MESSAGE_CREATE;

    /**
     * Handle the event.
     */
    public function handle(Message $message, Discord $discord): void
    {
        if (! Str::contains($message->content, 'laracord', ignoreCase: true)) {
            return;
        }

        $message->react('❤️');
    }
}

Tasks

Run timed tasks in the ReactPHP event loop

ReminderTask.php
<?php

namespace App\Tasks;

use Laracord\Tasks\Task;

class ReminderTask extends Task
{
    /**
     * The task interval.
     */
    protected int $interval = 5;

    /**
     * Determine if the task handler should execute during boot.
     */
    protected bool $eager = false;

    /**
     * Handle the task.
     */
    public function handle(): void
    {
        $this
            ->message('Hello world!')
            ->sendTo('453364472304762881');
    }
}

Middleware

Process commands and interactions with custom middleware

ExampleMiddleware.php
<?php

namespace App\Commands\Middleware;

use Closure;
use Laracord\Commands\Middleware\Context;
use Laracord\Commands\Middleware\Middleware;
use Laracord\Discord\Facades\Message;

class ExampleMiddleware implements Middleware
{
    /**
     * Handle the command.
     *
     * @return mixed
     */
    public function handle(Context $context, Closure $next)
    {
        if ($context->isCommand() && $context->command->getName() === 'ping') {
            Message::content('Not this time!')->reply($context->source);

            return;
        }

        return $next($context);
    }
}

A Solid Foundation for Your Next Discord Bot

Laracord provides a robust and developer-friendly base for crafting sophisticated Discord bots, leveraging proven PHP technologies.

Want to see what makes Laracord special? View the framework →

Get Started with Laracord in Seconds

Download Laracord, configure your Discord token, and boot your bot.

Step 1

Install Laracord

Get started with a single Composer command.

composer create-project laracord/laracord my-discord-bot
Step 2

Configure Your Bot

Add your Discord bot token to the .env file.

DISCORD_TOKEN=<token>
Step 3

Launch Your Bot

Launch your bot and begin interacting with Discord in real time.

php laracord

Frequently Asked Questions About Laracord

Everything you need to know about building Discord bots with Laravel and Laracord.

Laracord is a micro-framework that provides a powerful starting point for building Discord bots. It leverages the elegance of Laravel and the DiscordPHP library to enable developers to create functional, elegant bots with features like databases, caching, and more.
Laracord is built on Laravel Zero, a lightweight micro-framework for console applications. It incorporates familiar Laravel patterns such as Eloquent ORM, service providers, dependency injection, and Artisan-like commands (accessed via `php laracord`), making it accessible for Laravel developers while focusing on Discord bot development.
No, Laracord is designed as a standalone starting point using Laravel Zero for console-based applications like Discord bots. It is installed via `composer create-project`, creating a new project structure. It is not intended as a package to integrate directly into an existing Laravel web application. For integration needs, consider connecting via shared databases or APIs instead.
Not necessarily! Laracord abstracts much of the Discord API complexity through DiscordPHP, allowing you to build bots using Laravel-style syntax. Basic understanding of Discord concepts like intents, commands, and events is helpful but not required to get started.
Laracord supports all databases compatible with Laravel, including MySQL, PostgreSQL, and SQLite. You can use Eloquent models to manage Discord-related data, such as user preferences or server settings, leveraging Laravel's out-of-the-box database and caching features via Laravel Zero.
Yes! Laracord includes an optional HTTP server powered by ReactPHP, which supports Laravel routing for building APIs or webhooks. You can also integrate Laravel Livewire (installed separately via Composer) for real-time web interfaces, such as admin panels or dashboards that interact with your bot's data. However, the HTTP server is recommended for personal or internal use rather than public user-facing applications.

Ready to Build Something Amazing?

Join a growing community of developers building modern Discord bots powered by Laracord.