curiolabs / discord-php
一个与 Discord 音频和文本服务的非官方 API。
v5.0.11
2020-10-21 20:16 UTC
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-09-11 08:57:30 UTC
README
官方 Discord REST、网关和语音 API 的包装器。目前文档有限,所以请随时加入我们的 Discord 服务器 PHP Discorders,以获取有关库的任何问题。
为了测试和稳定性,如果您能将我们的测试机器人添加到您的服务器,我们将不胜感激。我们不会存储任何数据 - 机器人只是空闲,不与任何人互动,并用于测试与大量公会的大规模稳定性。您可以通过以下链接邀请机器人 此处。
常见问题解答
- 我可以在 web 服务器(例如 Apache、nginx)上运行 DiscordPHP 吗?
- 不行,DiscordPHP 只能在 CLI 中运行。如果您想为您的机器人提供界面,您可以将 react/http 集成到您的机器人中,并通过 CLI 运行它。
- PHP 内存不足?
- 尝试使用
ini_set('memory_limit', '-1');增加内存限制。
- 尝试使用
入门指南
需求
- PHP 7.3
- 技术上,库可以在 PHP 7.2 的某些版本上运行,但是不会支持低于 7.3 的任何版本。
- 需求将提高至 PHP 7.4,因此您应该为 PHP 的最新版本进行开发。
- Composer
ext-jsonext-zlib
推荐扩展
- 最新的 PHP 版本。
- 其中一个
ext-uv(首选)、ext-libev或evt-event以获得更快的、性能更好的事件循环。 - 如果处理非英语字符,则
ext-mbstring。
语音需求
- 64 位 Linux 或基于 Darwin 的操作系统。语音不能在 Windows 上运行。
ext-sodium- FFmpeg
安装 DiscordPHP
使用 Composer 安装 DiscordPHP。
- 运行
composer require team-reflex/discord-php。这将安装最新版本。- 如果您愿意,您也可以通过运行
composer require team-reflex/discord-php dev-master安装开发分支。
- 如果您愿意,您也可以通过运行
- 在主文件顶部包含 Composer 自动加载文件
include __DIR__.'/vendor/autoload.php';
- 制作一个机器人!
基本示例
<?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();
文档
原始文档可以在代码中找到,也可以在 DiscordPHP 类参考 中找到。更多用户友好型示例将很快在 DiscordPHP Wiki 上出现。
贡献
我们欢迎贡献。但是,请确保您遵循我们的编码标准(PSR-4 自动加载和自定义样式)。请在提交拉取请求之前运行 php-cs-fixer,通过运行 composer run-script cs。
许可证
MIT 许可证,© David Cole 和其他贡献者 2016--至今。