Discord bots and apps,
written in PHP.

DiscordPHP wraps Discord's REST, gateway and voice APIs for PHP. It runs on ReactPHP, keeps a live cache of the guilds, channels and members your bot can see, and handles slash commands, components, OAuth2 and voice.

—of — REST operations sent
—gateway events handled
—route diagrams
—the release the maps show

Quick start

DiscordPHP needs PHP 8.1.2 or newer with ext-json and ext-zlib, and runs from the command line, not a web server. On Windows, point openssl.cafile in php.ini at a CA certificate bundle first.

composer require team-reflex/discord-php
<?php

include __DIR__.'/vendor/autoload.php';

use Discord\Discord;
use Discord\Parts\Channel\Message;
use Discord\WebSockets\Event;
use Discord\WebSockets\Intents;

$discord = new Discord([
    'token' => 'bot-token',
    'intents' => Intents::getDefaultIntents(),
    // | Intents::MESSAGE_CONTENT, (privileged: see https://dis.gd/mcfaq)
]);

$discord->on('init', function (Discord $discord) {
    $discord->logger->info('Bot is ready!');

    $discord->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) {
        $discord->logger->info("{$message->author->username}: {$message->content}");
    });
});

$discord->run();

More in the examples folder.

From the maintainer: Frontier Systems

A cooperative, persistent engineering simulation in development. The early source prototype explores finite-resource mining, material transport, refining and physical construction. Moon and Mars colonies, spacecraft and orbital infrastructure are the longer-term vision.

Help fund initial development and follow verified milestones. Support is not a finished-game preorder or a promise of a release date.

Explore