exan / fenrir
Discord API & WS wrapper
Requires
- discord-php/http: ^v10.3.0
- evenement/evenement: ^3.0.0
- exan/eventer: ^1.0.3
- exan/reactphp-retrier: ^2.0
- freezemage0/array_find: ^1.0
- nesbot/carbon: ^2.64 || ^3.0
- ralouphie/mimey: ^1.0
- ratchet/pawl: ^0.4.1
- react/async: ^4.0.0
- react/event-loop: ^1.3.0
- react/promise: ^3
- spatie/regex: ^3.1
Requires (Dev)
- cboden/ratchet: ^0.4.4
- friendsofphp/php-cs-fixer: ^3.20
- mockery/mockery: ^1.6
- monolog/monolog: ^3.2
- phpmd/phpmd: ^2.13
- phpunit/phpunit: ^9.5 || ^10.0
- symfony/var-dumper: ^6.2
- dev-master
- 1.0.0
- 0.13.7
- 0.13.6
- 0.13.5
- 0.13.4
- 0.13.3
- 0.13.2
- 0.13.1
- 0.12.6
- 0.12.5
- 0.12.4
- 0.12.3
- 0.12.2
- 0.12.1
- 0.12.0
- 0.11.3
- 0.11.2
- 0.11.1
- 0.11.0
- 0.10.5
- 0.10.4
- 0.10.3
- 0.10.2
- 0.10.1
- 0.9.14
- 0.9.13
- 0.9.12
- 0.9.11
- 0.9.10
- 0.9.9
- 0.9.8
- 0.9.7
- 0.9.6
- 0.9.5
- 0.9.4
- 0.9.3
- 0.9.2
- 0.9.1
- 0.9.0
- 0.8.3
- 0.8.2
- 0.8.1
- 0.8.0
- 0.7.0
- 0.6.4
- 0.6.3
- 0.6.2
- 0.6.1
- 0.5.6
- 0.5.5
- 0.5.4
- 0.5.3
- 0.5.2
- 0.5.1
- 0.4.2
- 0.4.1
- 0.3.1
- 0.3.0
- 0.2.1
- 0.2.0
- 0.1.1
- 0.1.0
- 0.0.2
- 0.0.1
- dev-feature/http
- dev-feature/http-0.0.2
- dev-feature/orchestrator
- dev-feature/sharding-startup-delay
- dev-promise-v3-updated
- dev-chore/support-dec-24
- dev-tnapf-mapper
This package is auto-updated.
Last update: 2025-02-16 18:48:18 UTC
README
Fenrir
PHP Discord Interface.
About
Fenrir is a mostly plain wrapper over Discords APIs/gateway. There is no caching built in, this is for the user to implement themselves.
If you're looking for something thats easier to use, has caching OOTB, you could consider Laracord or DiscordPHP.
Fenrir heavily relies on ReactPHP for async operations. Knowing the basics of async PHP is recommended before diving in.
Install
composer require ragnarok/fenrir
Example bot
use Ragnarok\Fenrir\Bitwise\Bitwise; use Ragnarok\Fenrir\Constants\Events; use Ragnarok\Fenrir\Discord; use Ragnarok\Fenrir\Enums\Intent; use Ragnarok\Fenrir\Gateway\Events\MessageCreate; use Ragnarok\Fenrir\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 Ragnarok\Fenrir\Discord; use Ragnarok\Fenrir\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
Fenrir currently supports PHP 8.2+ Tests should pass nightly builds of newer versions, but this is not a supported usecase.
If you're using this in a Apache2/Nginx/etc webserver environment, you should probably limit yourself to only using Fenrir's 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!
Notice
The current underlying HTTP component is subject to change in the future. While the accesible API for it will remain similar, you should try to refrain from using it manually in your application.