almighty-shogun/discord-webhook
最新稳定版本:1.0.0
Composer 安装命令:
composer require almighty-shogun/discord-webhook
包简介
Personal implementation of Discord webhooks for PHP
README 文档
README
Personal implementation of Discord webhooks for PHP.
📃 Prerequisites
- PHP: >= v8.3
- Extension
ext-curlenabled in thephp.inifile.
💻 Installation
Step 1
Install the library via composer:
composer require almighty-shogun/discord-webhook
Step 2
Use the library in your project.
Using the classes
<?php use DiscordWebhook\DiscordWebhook; use DiscordWebhook\Error\DiscordWebhookException; use DiscordWebhook\Messages\{TextMessage, DiscordEmbed}; $discordWebhook = new DiscordWebhook("https://discord.com/api/webhooks/xxx/xxxx"); // Text message $message = new TextMessage(); $embed = new DiscordEmbed(); $embed->setTitle("Test Embed") ->setDescription("This is a test embed.") ->setColor("#228b22") // Hex color code without the # symbol. ->setURL("https://github.com/Almighty-Shogun") ->setFooter("Test Footer", "https://avatars.githubusercontent.com/u/96011415?v=4") ->setTimestamp() ->setThumbnail("https://avatars.githubusercontent.com/u/96011415?v=4") ->setImage("https://avatars.githubusercontent.com/u/96011415?v=4") ->setAuthor("Almighty Shogun", "https://avatars.githubusercontent.com/u/96011415?v=4") ->addField("Field 1", "This is a test field.") ->addField("Field 2", "This is another test field.") ->addField("Field 3", "This is a third test field."); $textMessage->setUsername("Almighty Shogun") ->setAvatar("https://avatars.githubusercontent.com/u/96011415?v=4") ->setContent("This is a test message."); try { $discordWebhook->send($textMessage); } catch (DiscordWebhookException $e) { echo $e->getMessage(); }
Using the helper functions
<?php $discordWebhook = discordWebhook("https://discord.com/api/webhooks/xxx/xxxx"); $embed = discordEmbed()->setTitle("Test Embed") ->setDescription("This is a test embed.") ->setColor("228b22") // Hex color code without the # symbol. ->setURL("https://github.com/Almighty-Shogun") ->setFooter("Test Footer", "https://avatars.githubusercontent.com/u/96011415?v=4") ->setTimestamp() ->setThumbnail("https://avatars.githubusercontent.com/u/96011415?v=4") ->setImage("https://avatars.githubusercontent.com/u/96011415?v=4") ->setAuthor("Almighty Shogun", "https://avatars.githubusercontent.com/u/96011415?v=4") ->addField("Field 1", "This is a test field.") ->addField("Field 2", "This is another test field.") ->addField("Field 3", "This is a third test field."); $textMessage = discordMessage() ->setUsername("Almighty Shogun") ->setAvatar("https://avatars.githubusercontent.com/u/96011415?v=4") ->setContent("This is a test message.") ->addEmbed($embed); try { $discordWebhook->send($textMessage); } catch (DiscordWebhookException $e) { echo $e->getMessage(); }
统计信息
- 总下载量: 2
- 月度下载量: 0
- 日度下载量: 0
- 收藏数: 0
- 点击次数: 0
- 依赖项目数: 0
- 推荐数: 0
其他信息
- 授权协议: MIT
- 更新时间: 2025-11-23