curiolabs / discord-php
An unofficial API to interact with the voice and text service Discord.
Requires
- php: ^7.2
- ext-json: *
- ext-zlib: *
- illuminate/support: ^4.0|^5.0|^6.0|^7.0|^8.0
- mollie/polyfill-libsodium: ^1.1
- monolog/monolog: ^2.1
- nesbot/carbon: ^2.38
- ratchet/pawl: 0.3.*
- react/datagram: 1.5.*
- react/http: ^1.1
- react/partial: ^3.0
- symfony/options-resolver: ^5.1.3
- trafficcophp/bytebuffer: ^0.3
Requires (Dev)
Suggests
- ext-event: For a faster, and more performant loop
- ext-libev: For a faster, and more performant loop
- ext-uv: For a faster, and more performant loop. PHP >=7 only. Preferred.
This package is auto-updated.
Last update: 2024-11-11 09:17:08 UTC
README
A wrapper for the official Discord REST, gateway and voice APIs. Documentation is limited at the moment so feel free to join our Discord server PHP Discorders for any questions relating to the library.
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.
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 increase your memory limit using
ini_set('memory_limit', '-1');
.
- Try increase your memory limit using
Getting Started
Requirements
- PHP 7.3
- Technically the library can run on some versions of PHP 7.2, however, no support will be given for any version lower than 7.3.
- The requirement will be increased to PHP 7.4 so you should develop for the latest version of PHP.
- Composer
ext-json
ext-zlib
Recommended Extensions
- The latest PHP version.
- One of
ext-uv
(preferred),ext-libev
orevt-event
for a faster, and more performant event loop. ext-mbstring
if handling non-english characters.
Voice Requirements
- 64-bit Linux or Darwin based OS. Voice does not run on Windows.
ext-sodium
- FFmpeg
Installing DiscordPHP
DiscordPHP is installed using Composer.
- Run
composer require team-reflex/discord-php
. This will install the lastest 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; $discord = new Discord([ 'token' => 'bot-token', ]); $discord->on('ready', function ($discord) { echo "Bot is ready!", PHP_EOL; // Listen for messages. $discord->on('message', function ($message, $discord) { echo "{$message->author->username}: {$message->content}",PHP_EOL; }); }); $discord->run();
Documentation
Raw documentation can be found in-line in the code and on the DiscordPHP Class Reference. More user friendly and examples will soon be coming on the DiscordPHP 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.