ricardosierra / discord-php
用于与语音和文本服务 Discord 交互的非官方 API。
v5.0.0
2020-06-08 04:53 UTC
Requires
- php: ^5.6|^7.0
- cache/array-adapter: >=0.4.0
- guzzlehttp/guzzle: ~5.3|>=6.0
- illuminate/support: ^4.0|^5.0|^6.0|^7.0|^8.0
- monolog/monolog: >=1.19
- nesbot/carbon: >=1.18
- ratchet/pawl: 0.*
- react/datagram: 1.*
- react/partial: >=2.0
- react/socket: >=0.4
- symfony/options-resolver: ^2.7|>=3.0
- trafficcophp/bytebuffer: >=0.3
- wyrihaximus/react-guzzle-psr7: >=1.0
Requires (Dev)
- symfony/var-dumper: ^2.7|^3.0
Suggests
- ext-event: For a faster, and more performant loop
- ext-libev: For a faster, and more performant loop
- ext-libevent: For a faster, and more performant loop. Preferred
- cache/apc-adapter: Required to use the APC cache driver
- cache/memcache-adapter: Required to use the Memcache cache driver
- cache/memcached-adapter: Required to use the Memcached cache driver
- cache/redis-adapter: Required to use the Redis cache driver
README
这个库目前已废弃,怀疑它根本无法工作,如果它能工作,那么bug实在太多,需要重写,但我真的不想这么做,抱歉。我们甚至制作了一个可以与 Discord 网关交互的 PHP 库,这本身就是一种奇迹,但是是时候说再见了。感谢所有一路以来帮助过我们的人,特别是 Aaron (@aequasi)。也许有一天有人可以接手并重写它。非常感谢,
- David
DiscordPHP
官方 Discord REST、网关和语音 API 的封装器。
常见问题解答
- 我可以在 web 服务器(例如 Apache、nginx)上运行 DiscordPHP 吗?
- 不行,DiscordPHP 只能在 CLI 中运行。如果你想为你的机器人提供一个界面,可以将 react/http 与你的机器人集成并通过 CLI 运行。
入门
安装 DiscordPHP
使用 Composer 安装 DiscordPHP。请确保你已经安装了 Composer 并熟悉其操作。我们需要的最小 PHP 版本是 PHP 5.5.9,但建议使用 PHP 7。PHP 5.x 支持 将在未来移除。
这个库尚未与 HHVM 测试。
- 运行
composer require team-reflex/discord-php
。这将安装最新版本。- 如果你想安装开发分支,可以运行
composer require team-reflex/discord-php dev-develop
。
- 如果你想安装开发分支,可以运行
- 在主文件顶部包含 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();
注意事项
- 这个库可能需要大量 RAM,PHP 可能会达到内存限制。为了增加内存限制,使用
ini_set('memory_limit', '200M')
将其增加到 200 MB。如果你想使其无限大,使用ini_set('memory_limit', '-1')
。
文档
原始文档可以在代码中找到,并在 DiscordPHP 类参考 中找到。更友好和示例文档将很快在 DiscordPHP Wiki 中出现。
贡献
我们欢迎贡献。但是,请确保你遵循我们的编码标准(PSR-4 自动加载和自定义样式)。我们使用 StyleCI 来格式化我们的代码。我们的 StyleCI 设置可以在 这里 找到。
库比较
查看 此图表 了解功能比较和其他 Discord API 库列表。