enlumop / discord-webhook-client
此包已被废弃,不再维护。未建议替代包。
专业的 Discord webhook 客户端库。
v0.0.2-alpha
2023-09-08 11:30 UTC
Requires
- php: >=8.1
- guzzlehttp/guzzle: ^7.7
- guzzlehttp/psr7: ^2.6
Requires (Dev)
- fakerphp/faker: ^1.23
- friendsofphp/php-cs-fixer: ^3.23
- phpstan/phpstan: ^1.10
- phpunit/phpunit: ^10.3
- symfony/console: ^6.3
- symfony/dotenv: ^6.3
This package is auto-updated.
Last update: 2024-04-08 19:09:21 UTC
README
徽章
源代码
最新版本
操作
目录
入门指南
需求
通过 Composer 安装
composer require enlumop/discord-webhook-client
简单示例
<?php use Enlumop\DiscordWebhooks\Embed; use Enlumop\DiscordWebhooks\Payload; use Enlumop\DiscordWebhooks\WebhookClient; // Create embed $embed = new Embed(); $embed->setDescription('This is an embed'); // with description $url = 'DISCORD_WEBHOOK_URL'; // Put your discord webhook url // Create Payload $payload = new Payload(); $payload->setUsername('Example Webhook Bot') // Change discord bot webhook username ->setMessage('This is a message') // Some text before embed ->addEmbed($embed) // Add embed ; // New discord webhook client $webhook = new WebhookClient(); // Send message $webhook->send($url, $payload);
许可协议
本项目采用 MIT 许可协议。要阅读完整的许可协议,请打开 LICENSE.md。
贡献
接受拉取请求和问题!
其他示例
仅消息,无嵌入
<?php use Enlumop\DiscordWebhooks\Payload; use Enlumop\DiscordWebhooks\WebhookClient; $url = 'DISCORD_WEBHOOK_URL'; // Put your discord webhook url // Create Payload $payload = new Payload(); $payload->setMessage('This is a message'); // Some text. If You need use the Message Builder // New discord webhook client $webhook = new WebhookClient(); // Send message $webhook->send($url, $payload);
消息构建器示例
<?php use Enlumop\DiscordWebhooks\Builder\TextFormattingCombine; use Enlumop\DiscordWebhooks\Builder\TextMessageBuilder; use Enlumop\DiscordWebhooks\Payload; use Enlumop\DiscordWebhooks\WebhookClient; $url = 'DISCORD_WEBHOOK_URL'; // Put your discord webhook url // Builder with on auto-newline mode (to disable auto-newline use new TextMessageBuilder(false)) $messageBuilder = new TextMessageBuilder(); $message = $messageBuilder->addText('<@ROLE_ID>') // ping some role ->addText('How are you?') // some text without format ->addBold("It's time for new webhook tool!") // **Text with bold** /** * Text with multiline codeblock: * ```php * // It's can using codeblock * ``` */ ->addMultilineCodeBlock("// It's can using codeblock", 'php') ->addQuoteBlock('And some quote!') // > Text with quote block ->addCombineTextFormatting( "It's awesome!!!111oneone", (new TextFormattingCombine()) ->withBold() ->withItalic() ->withUnderline() ) // ***__Text with: Bold, Italic and Underline__*** ->addText('Are you reade for this??') ->build() // build message (it was returned string) ; // Create Payload $payload = new Payload(); // Set message $payload->setMessage($message); // Send message $webhook = new WebhookClient(); $webhook->send($url, $payload);
您还可以使用 带嵌入的消息构建器,例如用于字段或描述。
文档和示例
要查看更多文档和示例,请点击 这里。