renzojohnson/discord-api
Composer 安装命令:
composer require renzojohnson/discord-api
包简介
Lightweight PHP wrapper for Discord REST API. Send messages, embeds, and files via webhooks and Bot tokens. Zero dependencies.
关键字:
README 文档
README
Lightweight PHP wrapper for Discord REST API v10. Zero dependencies.
Send messages, rich embeds, and files via webhooks and Bot tokens. Ed25519 interaction signature verification.
Author: Renzo Johnson
Requirements
- PHP 8.4+
- ext-curl
- ext-json
- ext-sodium (for interaction verification)
Installation
composer require renzojohnson/discord-api
Quick Start
use RenzoJohnson\Discord\Discord; $discord = new Discord('your-bot-token'); // Send a text message to a channel $discord->sendMessage('CHANNEL_ID', 'Hello from PHP!');
Bot API
Send Message
$discord->sendMessage('CHANNEL_ID', 'Hello World');
Send Embed
use RenzoJohnson\Discord\Message\Embed; $embed = (new Embed()) ->title('Server Alert') ->description('CPU usage is critical') ->color(0xFF0000) ->field('Server', 'web-01', inline: true) ->field('CPU', '95%', inline: true) ->footer('Monitoring Bot') ->timestamp(date('c')); $discord->sendEmbed('CHANNEL_ID', $embed); // Embed with text $discord->sendEmbed('CHANNEL_ID', $embed, content: 'Attention!');
Edit Message
$discord->editMessage('CHANNEL_ID', 'MESSAGE_ID', 'Updated content');
Delete Message
$discord->deleteMessage('CHANNEL_ID', 'MESSAGE_ID');
Add Reaction
$discord->addReaction('CHANNEL_ID', 'MESSAGE_ID', '👍');
Get Channel / Guild Channels
$channel = $discord->getChannel('CHANNEL_ID'); $channels = $discord->getGuildChannels('GUILD_ID');
Webhooks
No bot token needed — just a webhook URL.
use RenzoJohnson\Discord\Webhook\Webhook; $webhook = new Webhook('https://discord.com/api/webhooks/ID/TOKEN'); // Simple text $webhook->send('Deploy complete!'); // Rich embed use RenzoJohnson\Discord\Message\Embed; $embed = (new Embed()) ->title('Deployed v2.1.0') ->description('All systems operational') ->color(0x00FF00) ->footer('CI/CD Pipeline'); $webhook->sendEmbed($embed, content: 'Production deploy finished');
Webhook Message with Overrides
use RenzoJohnson\Discord\Message\WebhookMessage; $message = new WebhookMessage( content: 'Alert!', username: 'AlertBot', avatarUrl: 'https://example.com/bot.png', ); $embed = (new Embed())->title('Error')->description('Database connection failed')->color(0xFF0000); $message->addEmbed($embed); $webhook->send($message);
Embed Builder
Fluent API for building rich embeds.
$embed = (new Embed()) ->title('Title') ->description('Description text') ->url('https://example.com') ->color(0x5865F2) // Discord blurple ->author('Bot Name', 'https://example.com', 'https://example.com/icon.png') ->thumbnail('https://example.com/thumb.png') ->image('https://example.com/image.png') ->field('Field 1', 'Value 1', inline: true) ->field('Field 2', 'Value 2', inline: true) ->footer('Footer text', 'https://example.com/footer-icon.png') ->timestamp(date('c'));
Interaction Verification (Ed25519)
For Discord slash commands and interactions endpoint.
use RenzoJohnson\Discord\Webhook\InteractionVerifier; // Verify signature and get body $body = InteractionVerifier::verify('YOUR_PUBLIC_KEY'); $interaction = json_decode($body, true); // Respond to PING if ($interaction['type'] === 1) { InteractionVerifier::respondToPing(); }
Error Handling
use RenzoJohnson\Discord\Exception\AuthenticationException; use RenzoJohnson\Discord\Exception\RateLimitException; use RenzoJohnson\Discord\Exception\DiscordException; try { $discord->sendMessage('CHANNEL_ID', 'Hello'); } catch (AuthenticationException $e) { // Invalid bot token (401) } catch (RateLimitException $e) { $retryAfter = $e->getRetryAfter(); // seconds (float) } catch (DiscordException $e) { // Other API errors $errorData = $e->getErrorData(); }
Testing
composer install vendor/bin/phpunit
Links
License
MIT License. Copyright (c) 2026 Renzo Johnson.
renzojohnson/discord-api 适用场景与选型建议
renzojohnson/discord-api 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 2 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 02 月 24 日, 在 PHP 生态内属于活跃度较高的组件。
它主要适用于以下技术方向: 「php」 「notifications」 「messaging」 「chat」 「webhook」 「discord」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。
我们在过去多个企业项目中使用过 renzojohnson/discord-api 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。
基于 renzojohnson/discord-api 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。
线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。
承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。
与 renzojohnson/discord-api 相关的其它包
同方向 / 同关键字的高下载量 PHP Composer 包推荐,方便对比选型:
A Laravel Nova package that adds a notification feed in your Nova app.
PHP SDK for Mobile Message SMS API
Azure service bus Transport
Official PHP client for NATS messaging system
Captures outgoing SMS notifications
Alfabank REST API integration
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 38
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2026-02-24