team-reflex / discord-php
An unofficial API to interact with the voice and text service Discord.
Installs: 221 349
Dependents: 27
Suggesters: 3
Security: 0
Stars: 998
Watchers: 29
Forks: 237
Open Issues: 27
Requires
- php: ^8.0
- ext-json: *
- ext-zlib: *
- discord-php/http: ^10.1.7
- discord/interactions: ^2.2
- monolog/monolog: ^2.1.1 || ^3.0
- nesbot/carbon: ^2.38 || ^3.0
- psr/simple-cache: ^1.0 || ^2.0 || ^3.0
- ratchet/pawl: ^0.4.1
- react/async: ^4.0 || ^3.0
- react/cache: ^0.5 || ^0.6 || ^1.0
- react/child-process: ^0.6.3
- react/datagram: ^1.8
- react/event-loop: ^1.2
- react/promise: ^2.2
- symfony/options-resolver: ^5.1.11 || ^6.0 || ^7.0
- trafficcophp/bytebuffer: ^0.3
Requires (Dev)
- davidcole1340/reactsh: dev-master
- friendsofphp/php-cs-fixer: ^3
- phpunit/phpunit: ^9.4.4
- symfony/cache: ^5.4
- symfony/var-dumper: *
- wyrihaximus/react-cache-redis: ^3.0 || >=4.0 <4.4
Suggests
- ext-ev: For a faster, and more performant loop.
- ext-event: For a faster, and more performant loop.
- ext-fileinfo: For function mime_content_type().
- ext-gmp: For 64 bit calculations on x86 (32 bit) PHP.
- ext-mbstring: For accurate calculations of string length when handling non-english characters.
- ext-uv: For a faster, and more performant loop. Preferred.
- dev-master
- v10.0.0-RC12
- v10.0.0-RC11
- v10.0.0-RC10
- v10.0.0-RC9
- v10.0.0-RC8
- v10.0.0-RC7
- v10.0.0-RC6
- v10.0.0-RC5
- v10.0.0-RC4
- v10.0.0-RC3
- v10.0.0-RC2
- v10.0.0-RC1
- v7.x-dev
- v7.3.5
- v7.3.4
- v7.3.3
- v7.3.2
- v7.3.1
- v7.3.0
- v7.2.6
- v7.2.5
- v7.2.4
- v7.2.3
- v7.2.2
- v7.2.1
- v7.2.0
- v7.1.4
- v7.1.3
- v7.1.2
- v7.1.1
- v7.1.0
- v7.0.9
- v7.0.8
- v7.0.7
- v7.0.6
- v7.0.5
- v7.0.4
- v7.0.3
- v7.0.2
- v7.0.1
- v7.0.0
- v7.0.0-RC4
- v7.0.0-RC3
- v7.0.0-RC2
- v7.0.0-RC1
- v6.x-dev
- v6.0.3
- v6.0.2
- v6.0.1
- v6.0.0
- v6.0.0-RC4
- v5.2.0-RC3
- v5.2.0-RC2
- v5.2.0-RC1
- v5.1.x-dev
- v5.1.3
- v5.1.2
- v5.1.1
- v5.1.0
- v5.0.12
- v5.0.11
- v5.0.10
- v5.0.3
- v5.0.2
- v5.0.1
- v5.0.0
- v4.0.4
- v4.0.3
- v4.0.2
- v4.0.1
- v4.0.0
- v3.2.4
- v3.2.3
- v3.2.2
- 3.2.1
- v3.2.0
- v3.1.2
- v3.1.1
- v3.1.0
- v3.0.3
- v3.0.2
- v3.0.1
- v3.0.0
- v2.1.3
- v2.1.2
- v2.1.1
- v2.1.0
- v2.0.1
- v2.0.0
- v1.0.0
- dev-soundboards-events
- dev-entitlements
- dev-CommandBuilder-Save
- dev-valzargaming-polls
- dev-add/remove-role-enhancement
- dev-revert-1204-pruning-permission
- dev-pruning-permission
- dev-release-v10-notes
- dev-psr16-void-cache
- dev-subscriptions
- dev-promise-v3
- dev-valzargaming-patch-1
- dev-key2peace-patch-1
- dev-patch-docs
- dev-develop
This package is auto-updated.
Last update: 2024-11-01 18:50:50 UTC
README
A wrapper for the official Discord REST, gateway and voice APIs. Documentation is available here, albeit limited at the moment, as well as a class reference. Feel free to ask questions in the Discord server above.
For testing and stability it would be greatly appreciated if you were able to add our test bot to your server. We don't store any data - the bot simply idles and does not interact with anyone and is used to test stability with large numbers of guilds. You can invite the bot here.
Cache Interface (experimental)
Warning This branch contains an experimental feature, do not use it in production! See the wiki page for more information on how to set it up.
FAQ
- Can I run DiscordPHP on a webserver (e.g. Apache, nginx)?
- No, DiscordPHP will only run in CLI. If you want to have an interface for your bot you can integrate react/http with your bot and run it through CLI.
- PHP is running out of memory?
- Try unlimit your PHP memory using
ini_set('memory_limit', '-1');
.
- Try unlimit your PHP memory using
Getting Started
Before you start using this Library, you need to know how PHP works, you need to know how Event Loops and Promises work. This is a fundamental requirement before you start. Without this knowledge, you will only suffer.
Requirements
- PHP 8.0 or higher (latest version recommended)
- x86 (32-bit) PHP requires
ext-gmp
enabled.
- x86 (32-bit) PHP requires
ext-json
ext-zlib
Recommended Extensions
- One of
ext-uv
(recommended),ext-ev
orext-event
for a faster, and more performant event loop. ext-mbstring
if handling non-latin characters.
Voice Requirements
- 64-bit PHP
ext-sodium
- FFmpeg
Windows and SSL
Unfortunately PHP on Windows does not have access to the Windows Certificate Store. This is an issue because TLS gets used and as such certificate verification gets applied (turning this off is not an option).
You will notice this issue by your script exiting immediately after one loop turn without any errors.
As such users of this library need to download a Certificate Authority extract from the cURL website.
The path to the caextract must be set in the php.ini
for openssl.cafile
.
Installing DiscordPHP
DiscordPHP is installed using Composer.
- Run
composer require team-reflex/discord-php
. This will install the latest stable release.- If you would like, you can also install the development branch by running
composer require team-reflex/discord-php dev-master
.
- If you would like, you can also install the development branch by running
- Include the Composer autoload file at the top of your main file:
include __DIR__.'/vendor/autoload.php';
- Make a bot!
Basic Example
<?php include __DIR__.'/vendor/autoload.php'; use Discord\Discord; use Discord\Parts\Channel\Message; use Discord\WebSockets\Intents; use Discord\WebSockets\Event; $discord = new Discord([ 'token' => 'bot-token', 'intents' => Intents::getDefaultIntents() // | Intents::MESSAGE_CONTENT, // Note: MESSAGE_CONTENT is privileged, see https://dis.gd/mcfaq ]); $discord->on('ready', function (Discord $discord) { echo "Bot is ready!", PHP_EOL; // Listen for messages. $discord->on(Event::MESSAGE_CREATE, function (Message $message, Discord $discord) { echo "{$message->author->username}: {$message->content}", PHP_EOL; // Note: MESSAGE_CONTENT intent must be enabled to get the content if the bot is not mentioned/DMed. }); }); $discord->run();
See examples folder for more.
Documentation
Documentation for the latest version can be found here. Community contributed tutorials can be found on the wiki.
Contributing
We are open to contributions. However, please make sure you follow our coding standards (PSR-4 autoloading and custom styling). Please run php-cs-fixer before opening a pull request by running composer run-script cs
.
License
MIT License, © David Cole and other contributers 2016-present.