laravel-discord / yasmin
Requires
- php: ^7.3||^8.0
- ext-bcmath: *
- ext-date: *
- ext-filter: *
- ext-json: *
- ext-mbstring: *
- ext-openssl: *
- ext-pcre: *
- ext-zlib: *
- laravel-discord/collection: ^0.3.0
- laravel-discord/eventemitter: ^0.2.0
- laravel-discord/validator: ^0.4.0
- psr/http-message: ^1.0
- ratchet/pawl: ^0.3.1
- react/event-loop: ^1.0
- react/filesystem: ^0.1.1
- react/http: ^1.1
- react/promise: ^2.7.0
- ringcentral/psr7: ^1.2
- dev-master
- v1.2.0
- v1.1.0
- v1.0.6
- v1.0.5
- v1.0.4
- v1.0.3
- v1.0.2
- v1.0.1
- v1.0.0
- v1.0.0-beta.4
- v1.0.0-beta.3
- v1.0.0-beta.2
- v1.0.0-beta.1
- 0.9.x-dev
- v0.9.3
- v0.9.2
- v0.9.1
- v0.9.0
- v0.8.2
- v0.8.1
- v0.8.0
- v0.7.0
- v0.6.3
- v0.6.2
- v0.6.1
- v0.6.0
- v0.5.1
- v0.5.0
- v0.4.2
- v0.4.1
- v0.4.0
- dev-origin
- dev-experiment-client-container
- dev-experiment-reference
This package is auto-updated.
Last update: 2022-12-06 04:48:41 UTC
README
Yasmin 是一个用于 PHP 的 Discord API 库。Yasmin 可以连接到网关并交互 REST API。
此库仅适用于 PHP 7.1(及以后版本)和 CLI。Yasmin 只支持机器人账户。
分支版本
- 原始最终版本
0.7.0
https://github.com/laravel-discord/Yasmin/tree/origin - 原始 API 文档 https://laravel-discord.github.io/Yasmin/
- 最小变更版本
0.9.3
https://github.com/laravel-discord/Yasmin/tree/0.9
从 v1.0 开始,我将对代码进行重大更改。
composer require laravel-discord/yasmin
- 需要 PHP>=7.3
开始之前
在您开始使用此库之前,您需要了解 PHP 的工作原理,您需要了解语言,您还需要了解事件循环和承诺的工作方式。这是开始前的基本要求。没有这些知识,您只会受苦。
请参阅 https://github.com/elazar/asynchronous-php 以获取资源。
入门
使用 Yasmin 入门非常简单。您只需要使用 composer 安装 Yasmin 和其依赖项。然后,您可以将 composer 的自动加载器包含到您的文件中,并开始与 Discord 和 Yasmin 交互!
composer require charlottedunois/yasmin
监听 error
事件很重要。如果您没有附加 error
监听器,事件发射器将抛出异常。
确保您还有一个对所有承诺的拒绝处理程序,因为未处理的承诺拒绝会被吞没,您将永远不知道它们发生了什么。
重要信息:类实例上的所有属性(这意味着几乎所有属性)都是使用魔术方法实现的,如果属性不存在,则将抛出异常。
有一个 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
配置项。