sunxyw / discord-php
v4.0.3
2016-12-28 21:41 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
- 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
库已废弃,怀疑它根本不能正常工作,如果有,那么bug太多需要重写,我真的不想这样做,抱歉。我们甚至制作了一个与Discord网关交互的PHP库,这简直是个奇迹,但现在是时候说再见了。感谢所有帮助过我们的人,尤其是Aaron (@aequasi)。也许有一天,有人可以接手并重写。永远爱你们,
- David
DiscordPHP
官方Discord REST、网关和语音API的包装器。
常见问题解答
- 我可以在Web服务器(例如Apache、nginx)上运行DiscordPHP吗?
- 不可以,DiscordPHP只能在CLI上运行。如果你想给你的机器人一个界面,你可以将react/http与你的机器人集成,并通过CLI运行。
入门指南
安装DiscordPHP
DiscordPHP使用Composer安装。请确保你已经安装了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库列表。