labymod/discord-webhook-bundle

基于 labymod/discord-webhook 的 Discord Webhook Bundle

1.0.2 2022-01-26 17:10 UTC

This package is auto-updated.

Last update: 2024-09-04 16:22:12 UTC


README

Latest Stable Version Total Downloads License

Symfony Bundle for labymod/discord-webhook. 在您的 Symfony 应用程序中轻松配置 webhooks

版本和兼容性

安装

Composer 安装

composer require labymod/discord-webhook-bundle

Symfony 配置和使用

  1. config/bundles.php 中启用此包
    return [
        // ...
        \DiscordWebhookBundle\DiscordWebhookBundle::class => ['all' => true],
    ]
  2. 添加全局和/或基于环境的配置文件: config/[env]/discord_webhook.yaml

配置参考

# Default configuration
discord_webhook:
    default_url:          ~ # required, The Webhook URL for the default service.
    clients:
        # Prototype
        name: # choose a name (service-id) for your preconfigured client
            webhook_url:          ~ # required, The Discord Webhook URL for this client.
            username:             null # optional, The username for the Discord bot.
            avatar_url:           null # optional, URL which is used for the Bot avatar.

使用方法

默认客户端

配置了 discord_webhook.default_url 后,基本服务(DiscordWebhookBundle\DiscordWebhook)将配置并公开在服务容器中

额外的命名客户端

如果您配置了一个或多个如下所示的命名客户端,您可以通过其名称以两种方式访问它们。

discord_webhook
    # ...
    clients:
        announcements.client:
            webhook_url: 'https://discord.com/my/webhook/url'

现在这个客户端也作为服务可用

use DiscordWebhookBundle\DiscordWebhook;

class MyController
{
   public function myAction(DiscordWebhook $announcementsClient) // <-- Thanks to an ArgumentValueResolver, name the parameter after your client, and it will be resolved automatically
   {
      // OR, resolve it from the container:
      $webhook = $this->container->get('announcements.client');
   }
}

文档

有关如何使用 Webhooks 的详细文档,请参阅底层库
https://github.com/LabyMod/discord-webhook/blob/master/README.md

有关更多文档,请查看此处