cyberwolf-studio / discord-php
Discord API & Gateway wrapper for PHP. A rebranded, maintained fork of Ragnarok/Fenrir.
Requires
- php: ^8.5
- discord-php/http: ^v10.3.0
- evenement/evenement: ^3.0.0
- exan/eventer: ^1.0.3
- exan/reactphp-retrier: ^2.0
- nesbot/carbon: ^3.0
- ralouphie/mimey: ^1.0
- ratchet/pawl: ^0.4.3
- react/async: ^4.0.0
- react/event-loop: ^1.3.0
- react/promise: ^3
Requires (Dev)
- friendsofphp/php-cs-fixer: ^3.20
- mockery/mockery: ^1.6
- monolog/monolog: ^3.2
- phpunit/phpunit: ^9.5 || ^10.0
- symfony/var-dumper: ^6.2 || ^7.0 || ^8.0
This package is auto-updated.
Last update: 2026-08-26 13:22:51 UTC
README
Discord PHP
PHP Discord Interface — API & Gateway wrapper.
About
Discord PHP is a mostly plain wrapper over Discord's APIs/gateway. There is no caching built in; this is for the user to implement themselves.
It heavily relies on ReactPHP for async operations. Knowing the basics of async PHP is recommended before diving in.
Discord PHP is a rebranded, maintained fork of Fenrir by Ragnarök. See Credits below.
Install
composer require cyberwolf-studio/discord-php
Example bot
use CyberWolf\Discord\Bitwise\Bitwise; use CyberWolf\Discord\Constants\Events; use CyberWolf\Discord\Discord; use CyberWolf\Discord\Enums\Intent; use CyberWolf\Discord\Gateway\Events\MessageCreate; use CyberWolf\Discord\Rest\Helpers\Channel\MessageBuilder; require './vendor/autoload.php'; $discord = new Discord('TOKEN'); $discord ->withGateway(Bitwise::from( Intent::GUILD_MESSAGES, Intent::DIRECT_MESSAGES, Intent::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->open(); // Nothing after this line is executed
REST-only example
use CyberWolf\Discord\Discord; use CyberWolf\Discord\Rest\Helpers\Channel\MessageBuilder; require './vendor/autoload.php'; $discord = new Discord('TOKEN'); $discord->withRest(); $discord->rest->channel->createMessage( 'channel-id', (new MessageBuilder()) ->setContent('Hi there!') );
(Note: going with REST-only means you do NOT receive any events and your bot will appear offline)
For more examples, check out the examples directory.
Support
Discord PHP currently supports PHP 8.5+. Tests should pass on nightly builds of newer versions, but this is not a supported usecase.
Note: Bugfixes/features will not be backported to older versions. Older versions are as-is.
If you're using this in an Apache2/Nginx/etc webserver environment, you should probably limit yourself to only using the REST capabilities. These environments typically don't allow long-running processes.
32-bit is not supported, though no hard limit is in place.
Contributing
Contributions are welcome.
You can look for @todo to find something that requires attention.
Please make sure to write tests where possible & make sure your code matches the phpcs configuration.
Thanks!
Credits
Discord PHP is a fork of Fenrir, originally created by Ragnarök and released under the MIT License. All original copyright is retained in LICENSE. Huge thanks to the original authors and contributors for the foundation this project is built on.
Notice
The current underlying HTTP component is subject to change in the future. While the accessible API for it will remain similar, you should try to refrain from using it manually in your application.
License
Released under the MIT License. See LICENSE for the full text, including the original Fenrir copyright.