zinntikumugai / discord-php
此包已被废弃,不再维护。未建议替代包。
与 Discord 语音和文本服务交互的非官方 API。
v4.0.4
2018-02-16 15:52 UTC
Requires
- php: ^5.6|^7.0
- cache/array-adapter: ^0.4.2
- guzzlehttp/guzzle: ~5.3|~6.0
- illuminate/support: ^4.0|^5.0
- monolog/monolog: ^1.19
- nesbot/carbon: ^1.18
- ratchet/pawl: 0.2.*
- react/datagram: 1.1.*
- react/partial: ^2.0
- react/socket-client: 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
使用时可能无法达到预期效果,怎么办
- 本地化为日语
- Samurai 样式的 UI
请稍等
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 库的列表。