承接 renzojohnson/discord-api 相关项目开发

从需求分析到上线部署,全程专人跟进,保证项目质量与交付效率

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

renzojohnson/discord-api

最新稳定版本:v1.0.0

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

Latest Version PHP Version License

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.

统计信息

  • 总下载量: 2
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 3
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-02-24

承接程序开发

PHP开发

VUE

Vue开发

前端开发

小程序开发

公众号开发

系统定制

数据库设计

云部署

网站建设

安全加固