justinkluever/discord-webhook-builder

GitHub: justinkluever/discord-webhook-builder

一个 PHP 库,通过流式 API 帮助开发者便捷地构建 Discord Webhook 消息体。

Stars: 0 | Forks: 0

# Discord Webhook Builder 一个简单的 Discord webhook builder。 该包仅提供一种流畅的方式来构建 payload,目前你仍需自行发送它。 你可以通过 composer 进行安装: ``` composer require justinkluever/discord-webhook-builder ``` ## 用法 使用此包应该非常简单: ``` use JustinKluever\DiscordWebhookBuilder\Components\TextDisplay; use JustinKluever\DiscordWebhookBuilder\Enums\Support\MessageFlag; use JustinKluever\DiscordWebhookBuilder\Support\Webhook\Embed; use JustinKluever\DiscordWebhookBuilder\Webhook; // Components V2 $webhook = Webhook::make() ->flag(MessageFlag::IS_COMPONENTS_V2) // Required for Components V2 by Discord ->component( TextDisplay::make('This is a Text Display!'), ); // Classic Webhooks $webhook = Webhook::make() ->content('Embed Test webhook') ->embed( Embed::make()->description('This is a Embed description'), ) ``` 在创建了你的 webhook payload 之后,你可以使用你偏好的方式进行 POST 请求: ``` // Laravel HTTP Client use Illuminate\Support\Facades\Http; Http::post('https://discord.com/api/webhooks/...', $webhook); // The Webhook builder implements Stringable for ease of use // Guzzle $client->post('https://discord.com/api/webhooks/...', [ 'json' => $webhook ]); // cURL $ch = curl_init('https://discord.com/api/webhooks/...'); curl_setopt($ch, CURLOPT_HTTPHEADER, ['Content-Type: application/json']); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $webhook); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); $response = curl_exec($ch); curl_close($ch); ``` 有关如何使用特定组件的更多细节,请查看源码或参阅 Discord 的文档: - [Discord Webhook 文档](https://docs.discord.com/developers/resources/webhook) - [Discord 组件文档](https://docs.discord.com/developers/components/reference#component-object) ## 许可证 The MIT License (MIT)。请查看[许可证文件](LICENSE.md)了解更多信息。
标签:Discord, ffuf, OpenVAS, PHP, Webhook, 力导向图, 开发库, 流式构建器