承接 larafystudios/discord-webhooks 相关项目开发

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

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

larafystudios/discord-webhooks

Composer 安装命令:

composer require larafystudios/discord-webhooks

包简介

A simple, elegant Laravel package for sending Discord webhook messages with support for text content, embeds, and rich formatting.

README 文档

README

A simple, elegant, and feature-rich Laravel package for sending Discord webhook messages with support for text content, embeds, and rich formatting.

Requirements

  • PHP 8.2 or higher
  • Laravel 11.x or 12.x

Installation

Install the package via Composer:

composer require larafystudios/discord-webhooks

The package will automatically register its service provider and facade.

Configuration

Publish Configuration (Optional)

If you want to customize the default configuration, publish the config file:

php artisan vendor:publish --tag=discord-webhooks-config

This will create a config/discord-webhooks.php file in your project.

Environment Variables

You can configure the package using environment variables in your .env file:

DISCORD_WEBHOOK_URL=https://discord.com/api/webhooks/your-webhook-url
DISCORD_WEBHOOK_USERNAME="Laravel Application"
DISCORD_WEBHOOK_AVATAR_URL=https://example.com/avatar.png

Usage

Basic Text Message

Send a simple text message:

use LarafyStudios\DiscordWebhooks\DiscordWebhook;

DiscordWebhook::make()
    ->setContent('Hello from Laravel!')
    ->send();

Using the Facade

You can also use the provided facade:

use DiscordWebhook;

DiscordWebhook::make()
    ->setContent('Hello from Laravel!')
    ->send();

Custom Webhook URL

Specify a different webhook URL for a specific message:

DiscordWebhook::make('https://discord.com/api/webhooks/your-custom-webhook-url')
    ->setContent('Custom webhook message')
    ->send();

Customize Username and Avatar

Set a custom username and avatar for the webhook:

DiscordWebhook::make()
    ->setUsername('My Custom Bot')
    ->setAvatarUrl('https://example.com/avatar.png')
    ->setContent('Hello with custom identity!')
    ->send();

Rich Embeds

Create beautiful embed messages:

DiscordWebhook::make()
    ->setContent('Check out this embed!')
    ->addEmbed(function ($embed) {
        $embed->setTitle('Embed Title', 'https://example.com')
              ->setDescription('This is a detailed description of the embed content.')
              ->setColor(0x3498db) // Blue color
              ->addField('Field 1', 'Value 1', true)
              ->addField('Field 2', 'Value 2', true)
              ->addField('Field 3', 'This is a longer value that spans multiple lines', false)
              ->setFooter('Footer text', 'https://example.com/footer-icon.png')
              ->setTimestamp();
    })
    ->send();

Embed Only (No Text)

Send an embed without text content:

DiscordWebhook::make()
    ->addEmbed(function ($embed) {
        $embed->setTitle('Notification')
              ->setDescription('This is an embed-only message')
              ->setColor(0x00ff00) // Green
              ->setTimestamp();
    })
    ->send();

Multiple Embeds

Add multiple embeds to a single message:

DiscordWebhook::make()
    ->setContent('Multiple embeds example')
    ->addEmbed(function ($embed) {
        $embed->setTitle('First Embed')
              ->setDescription('This is the first embed')
              ->setColor(0xff0000); // Red
    })
    ->addEmbed(function ($embed) {
        $embed->setTitle('Second Embed')
              ->setDescription('This is the second embed')
              ->setColor(0x0000ff); // Blue
    })
    ->send();

Using Embed Instance Directly

You can also create and pass an embed instance directly:

use LarafyStudios\DiscordWebhooks\DiscordEmbed;

$embed = new DiscordEmbed();
$embed->setTitle('Direct Embed')
      ->setDescription('Created directly')
      ->setColor(0xffff00);

DiscordWebhook::make()
    ->setContent('Using direct embed instance')
    ->addEmbed($embed)
    ->send();

Method Chaining

All methods support fluent chaining:

DiscordWebhook::make()
    ->setUsername('My Bot')
    ->setAvatarUrl('https://example.com/avatar.png')
    ->setContent('Chained methods example')
    ->addEmbed(function ($embed) {
        $embed->setTitle('Title')
              ->setDescription('Description')
              ->setColor(0x3498db)
              ->setAuthor('Author Name', 'https://example.com', 'https://example.com/author.png')
              ->setThumbnail('https://example.com/thumbnail.png')
              ->setImage('https://example.com/image.png')
              ->addField('Inline Field 1', 'Value', true)
              ->addField('Inline Field 2', 'Value', true)
              ->addField('Full Width Field', 'Value', false)
              ->setFooter('Footer', 'https://example.com/footer.png')
              ->setTimestamp();
    })
    ->send();

API Reference

DiscordWebhook Methods

Method Description Parameters
make(?string $url = null) Create a new webhook instance $url - Optional webhook URL
setContent(string $content) Set the message text content $content - The message text
setUsername(string $username) Set the webhook username $username - The username
setAvatarUrl(string $avatarUrl) Set the webhook avatar URL $avatarUrl - The avatar URL
addEmbed(callable|DiscordEmbed $embed) Add an embed to the message $embed - Callback or embed instance
send() Send the webhook message Returns bool

DiscordEmbed Methods

Method Description Parameters
setTitle(string $title, ?string $url = null) Set the embed title $title - Title text, $url - Optional title URL
setDescription(string $description) Set the embed description $description - Description text
setColor(int $color) Set the embed color $color - Hex color as integer (e.g., 0x3498db)
setTimestamp(?\DateTimeInterface $timestamp = null) Set the embed timestamp $timestamp - Optional timestamp (defaults to now)
setFooter(string $text, ?string $iconUrl = null) Set the embed footer $text - Footer text, $iconUrl - Optional icon URL
setImage(string $url) Set the embed image $url - Image URL
setThumbnail(string $url) Set the embed thumbnail $url - Thumbnail URL
setAuthor(string $name, ?string $url = null, ?string $iconUrl = null) Set the embed author $name - Author name, $url - Optional author URL, $iconUrl - Optional icon URL
addField(string $name, string $value, bool $inline = false) Add a field to the embed $name - Field name, $value - Field value, $inline - Whether field is inline

Error Handling

The send() method returns boolean:

  • true if the webhook was sent successfully
  • false if the webhook failed to send

Errors are automatically logged to Laravel's log system. If the webhook URL is not set, an InvalidArgumentException will be thrown during instantiation.

Examples

Notification System

// In your User model or event listener
use LarafyStudios\DiscordWebhooks\DiscordWebhook;

public function notifyNewUser($user)
{
    DiscordWebhook::make()
        ->setContent("New user registered: {$user->name}")
        ->addEmbed(function ($embed) use ($user) {
            $embed->setTitle('New User Registration')
                  ->setDescription("User {$user->name} ({$user->email}) has registered.")
                  ->setColor(0x00ff00)
                  ->addField('User ID', (string) $user->id, true)
                  ->addField('Email', $user->email, true)
                  ->setTimestamp();
        })
        ->send();
}

Error Reporting

try {
    // Your code here
} catch (\Exception $e) {
    DiscordWebhook::make()
        ->setContent('⚠️ An error occurred in the application')
        ->addEmbed(function ($embed) use ($e) {
            $embed->setTitle('Error Report')
                  ->setDescription($e->getMessage())
                  ->setColor(0xff0000)
                  ->addField('File', $e->getFile(), false)
                  ->addField('Line', (string) $e->getLine(), true)
                  ->setTimestamp();
        })
        ->send();
}

Testing

When testing your application, you may want to prevent actual webhook calls. You can mock the Http facade or use a test webhook URL.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

The MIT License (MIT). Please see License File for more information.

Support

For issues, questions, or contributions, please visit the GitHub repository.

Made with ❤️ by LarafyStudios

larafystudios/discord-webhooks 适用场景与选型建议

larafystudios/discord-webhooks 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 1 次下载、GitHub Stars 达 0, 最近一次更新时间为 2026 年 01 月 22 日, 在 PHP 生态内属于活跃度较高的组件。

它主要适用于以下技术方向: 「notification」 「laravel」 「embed」 「webhook」 「discord」 「laravel-package」 等业务场景。在实际项目中,围绕这些方向常见需要落地的问题包括:接口对接、性能调优、并发安全、与既有框架(Laravel / ThinkPHP / Yii / Webman 等)的兼容适配,以及生产环境的日志埋点与稳定性保障。

我们在过去多个企业项目中使用过 larafystudios/discord-webhooks 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 larafystudios/discord-webhooks 我们能提供哪些服务?
定制开发 / 二次开发

基于 larafystudios/discord-webhooks 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

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

GitHub 信息

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

其他信息

  • 授权协议: MIT
  • 更新时间: 2026-01-22