almighty-shogun/discord-webhook 问题修复 & 功能扩展

解决BUG、新增功能、兼容多环境部署,快速响应你的开发需求

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

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-curl enabled in the php.ini file.

💻 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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2025-11-23