xety / yasmin
Yasmin 是一个用于 PHP 的 Discord API 库。Yasmin 连接到网关并与 REST API 交互。
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
- xety/collection: ^0.3.0
- xety/eventemitter: ^0.2.0
- xety/validator: ^0.3.0
This package is auto-updated.
Last update: 2024-09-21 07:54:48 UTC
README
Yasmin 是一个用于 PHP 的 Discord API 库。Yasmin 连接到网关并与 REST API 交互。
注意:此库仅适用于 PHP 7.1(及更高版本)和 CLI 使用。Yasmin 仅支持机器人账号。
开始前
在使用此库之前,您必须了解 PHP 的工作原理,您需要了解该语言,您还需要了解事件循环和承诺的工作方式。这是开始前的基本要求。没有这些知识,您只会遭受痛苦。
请参阅 https://github.com/elazar/asynchronous-php 以获取资源。
入门
使用 Yasmin 入门非常直接。您需要做的就是使用 composer 安装 Yasmin 及其依赖项。之后,您可以将 composer 的自动加载器包含到您的文件中,并开始与 Discord 和 Yasmin 交互!
composer require charlottedunois/yasmin
监听错误事件非常重要。如果您没有附加错误监听器,事件发射器将抛出异常。
确保您还为所有承诺设置了拒绝处理器,因为未处理的承诺拒绝将被吞没,您将永远不会知道它们发生了什么。
重要信息:类实例上所有使用魔术方法实现(这意味着几乎所有属性)的属性,如果属性不存在,将抛出异常。
存在一个 WIP Gitbook,其中包含一些提示,请随意阅读:https://charlottedunois.gitbooks.io/yasmin-guide/content/
示例
这是一个使用 Yasmin 的简单示例。您应将所有监听器代码放入 try-catch 块中,并相应地处理异常。
// 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();
语音支持
没有语音支持。
文档
https://charlottedunois.github.io/Yasmin/
Windows 和 SSL
很遗憾,Windows 上的 PHP 无法访问 Windows 证书存储。这是一个问题,因为 TLS 被使用,因此证书验证被应用(关闭此选项不是一种选择)。
您将注意到这个问题,因为您的脚本在没有任何错误的情况下立即在循环中退出一次。遗憾的是,没有错误或异常。
因此,此库的用户需要从 cURL 网站下载一个 证书颁发机构提取。
caextract 的路径必须在 php.ini
中设置为 openssl.cafile
。