定制 nomanhameed/laravel-discord-notify 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

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

nomanhameed/laravel-discord-notify

最新稳定版本:v1.0.2

Composer 安装命令:

composer require nomanhameed/laravel-discord-notify

包简介

A Laravel package for sending notifications to Discord channels via webhooks with rich embed support.

README 文档

README

Latest Version on Packagist Total Downloads License

A Laravel package for sending notifications to Discord channels via webhooks with rich embed support.

Installation

Install the package via Composer:

composer require nomanhameed/laravel-discord-notify

The package will automatically register itself.

Configuration

Publish the configuration file:

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

Add your Discord webhook URLs to your .env file:

DISCORD_GENERAL_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN
DISCORD_ALERTS_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN
DISCORD_LOGS_WEBHOOK_URL=https://discord.com/api/webhooks/YOUR_WEBHOOK_ID/YOUR_WEBHOOK_TOKEN

# Optional settings
DISCORD_DEFAULT_USERNAME="Laravel Bot"
DISCORD_TIMEOUT=10
DISCORD_LOG_ERRORS=true
DISCORD_THROW_EXCEPTIONS=false

Usage

Basic Usage

use NomanHameed\DiscordNotify\Facades\Discord;

// Send a simple message
Discord::sendToChannel('general', 'Hello from Laravel!');

// Send with embeds
$embed = Discord::createEmbed(
    'New Order',
    'Order #12345 has been placed',
    0x00ff00,
    [
        Discord::createField('Customer', 'John Doe', true),
        Discord::createField('Amount', '$99.99', true),
    ]
);

Discord::sendToChannel('orders', null, [$embed]);

Using the Service

use NomanHameed\DiscordNotify\Services\DiscordService;

class OrderController extends Controller
{
    public function store(Request $request, DiscordService $discord)
    {
        // ... create order logic
        
        $discord->sendToChannel('orders', "New order: #{$order->id}");
    }
}

Advanced Usage

// Send to multiple channels
Discord::sendToMultipleChannels(['general', 'alerts'], 'System maintenance in 5 minutes');

// Send directly to webhook
Discord::sendToWebhook($webhookUrl, 'Direct message');

// Create rich embeds
$embed = Discord::createEmbed(
    title: 'System Alert',
    description: 'High CPU usage detected',
    color: 0xff0000,
    fields: [
        Discord::createField('Server', 'web-01', true),
        Discord::createField('CPU Usage', '95%', true),
    ],
    footer: 'Monitoring System',
    thumbnail: 'https://example.com/alert-icon.png'
);

Discord::sendToChannel('alerts', null, [$embed]);

Using Notifications

use NomanHameed\DiscordNotify\Notifications\DiscordNotification;

// In your notification class
public function toDiscord($notifiable)
{
    return (new DiscordNotification())
        ->content('Your order has been shipped!')
        ->to(config('discord-notifications.channels.orders.webhook_url'))
        ->username('Order Bot')
        ->embeds([
            Discord::createEmbed('Order Shipped', 'Tracking: 1234567890')
        ]);
}

Features

  • ✅ Send messages to multiple Discord channels
  • ✅ Rich embed support
  • ✅ Custom usernames and avatars per channel
  • ✅ Text-to-speech support
  • ✅ Laravel notification integration
  • ✅ Facade support
  • ✅ Configurable error handling
  • ✅ Timeout configuration

Getting Discord Webhook URLs

  1. Go to your Discord server
  2. Right-click on the channel
  3. Select "Edit Channel"
  4. Go to "Integrations" → "Webhooks"
  5. Click "Create Webhook"
  6. Copy the webhook URL

Configuration Options

The config/discord-notifications.php file contains all configuration options:

  • default_username: Default bot username
  • default_avatar_url: Default bot avatar
  • timeout: Request timeout in seconds
  • channels: Array of channel configurations
  • log_errors: Whether to log errors
  • throw_exceptions: Whether to throw exceptions on failure

Contributing

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

Issues

If you discover any issues, please report them via GitHub Issues.

Credits

License

This package is open-sourced software licensed under the MIT license.

统计信息

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

GitHub 信息

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

其他信息

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