Skip to content
Exanlv edited this page Mar 27, 2023 · 11 revisions

Fenrir, a standalone PHP library for interacting with both Discord's Gateway and REST API. This library gives you low-level control over the interaction with Discord, allowing for complete customization of your bot or application.

Basic ping-pong bot example:

use Exan\Fenrir\Bitwise\Bitwise;
use Exan\Fenrir\Constants\Events;
use Exan\Fenrir\Discord;
use Exan\Fenrir\Enums\Gateway\Intents;
use Exan\Fenrir\Rest\Helpers\Channel\MessageBuilder;
use Exan\Fenrir\Websocket\Events\MessageCreate;

require './vendor/autoload.php';

$discord = new Discord('TOKEN');

$discord
    ->withGateway(Bitwise::from(
        Intents::GUILD_MESSAGES,
        Intents::DIRECT_MESSAGES,
        Intents::MESSAGE_CONTENT,
    ))
    ->withRest();

$discord->gateway->events->on(Events::MESSAGE_CREATE, function (MessageCreate $message) use ($discord) {
    if ($message->content === '!ping') {
        $discord->rest->channel->createMessage(
            $message->channel_id,
            (new MessageBuilder())
                ->setContent('pong!')
        );
    }
});

$discord->gateway->connect(); // Nothing after this line is executed
Clone this wiki locally