shanemcc / yasmin
Yasmin is a Discord API library for PHP.
Requires
- php: >=7.1
- ext-bcmath: *
- ext-date: *
- ext-filter: *
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
- ext-pcre: *
- ext-zlib: *
- clue/buzz-react: ^2.6.0
- psr/http-message: ^1.0
- ratchet/pawl: ^0.3.1
- react/event-loop: ^1.0|^0.5|^0.4.3
- react/filesystem: ^0.1.1
- react/promise: ^2.7.0
- ringcentral/psr7: ^1.2
- valzargaming/collection: ^0.2.0
- valzargaming/eventemitter: ^0.1.5
- valzargaming/validator: ^0.3.0
Replaces
- charlottedunois/yasmin: v0.7.6
- valzargaming/yasmin: v0.7.6
This package is auto-updated.
Last update: 2024-10-20 09:47:41 UTC
README
Note: This is a fork of the original CharlotteDunois/Yasmin repo with additional fixes from other forks.
Yasmin
Yasmin is a Discord API library for PHP. Yasmin connects to the Gateway and interacts with the REST API.
This library is only for PHP 7.1 (and later) and use in CLI. Only bot accounts are supported by Yasmin.
Before you start
Before you start using this Library, you need to know how PHP works, you need to know the language and 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.
See https://github.com/elazar/asynchronous-php for resources.
Getting Started
Getting started with Yasmin is pretty straight forward. All you need to do is to use composer to install Yasmin and its dependencies. After that, you can include composer's autoloader into your file and start interacting with Discord and Yasmin!
composer require shanemcc/yasmin:"dev-master as 1.0.x-dev"
It is important to listen to error
events. If you don't attach an error
listener, the event emitter will throw an exception.
Make sure you also have a rejection handler for all promises, as unhandled promise rejections get swallowed and you will never know what happened to them.
Important Information: All properties on class instances, which are implemented using a magic method (which means pretty much all properties), are throwing if the property doesn't exist.
There is a WIP Gitbook with a few protips in it, feel free to read it: https://charlottedunois.gitbooks.io/yasmin-guide/content/
Example
This is a fairly trivial example of using Yasmin. You should put all your listener code into try-catch blocks and handle exceptions accordingly.
// Include composer autoloader $loop = \React\EventLoop\Factory::create(); $client = new \CharlotteDunois\Yasmin\Client(array(), $loop); $client->on('error', function ($error) { echo $error.PHP_EOL; }); $client->on('ready', function () use ($client) { echo 'Logged in as '.$client->user->tag.' created on '.$client->user->createdAt->format('d.m.Y H:i:s').PHP_EOL; }); $client->on('message', function ($message) { echo 'Received Message from '.$message->author->tag.' in '.($message->channel instanceof \CharlotteDunois\Yasmin\Interfaces\DMChannelInterface ? 'DM' : 'channel #'.$message->channel->name ).' with '.$message->attachments->count().' attachment(s) and '.\count($message->embeds).' embed(s)'.PHP_EOL; }); $client->login('YOUR_TOKEN')->done(); $loop->run();
Voice Support
There is no voice support.
Documentation
https://shanemcc.github.io/Yasmin/
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. Unfortunately there is for some reason no error or exception.
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
.
Linux Support
Use git to clone this repository.
Yasmin requires PHP 7.1+ to run, as well as the following packages. It's recommended to use the latest version of php available in your repository. In the example provided, 7.1 will be used. Replace 7.1 with the version you're currently using.
Ubuntu
sudo apt install openssl php7.1 php7.1-bcmath php7.1-mbstring
Notice of limited support
I cannot provide support with most issues that occur due to outdated prerequisites or implementing SSL. If you are hosting on Windows and needing a cacert.pem file but don't feel comfortable generating yourself then I personally recommend WinNMP as it generates one in its /data/ directory that you can point your PHP.ini at.
Other distros
Please refer to your distros repository to find the packages above.