auroraari/discord-webhooks

此包已被废弃且不再维护。未建议替代包。

一个轻量级的 Discord Webhooks 使用封装器

v1.0 2016-10-28 17:33 UTC

This package is not auto-updated.

Last update: 2018-11-29 21:34:49 UTC


README

一个轻量级的封装器,用于与 Discord Webhooks 交互!

入门指南

此封装器通过使用 Composer 安装。您还需要安装(至少)PHP 5.3,以及 ext-curl。此封装器尚未在 HHVM 上进行测试,但没有任何理由它不能工作!

  1. 运行 composer require auroraari/discord-webhooks 安装最新版本。
  2. 在文件顶部包含 Composer 自动加载文件
    • include __DIR__.'/vendor/autoload.php';
  3. 享受吧!

在 Discord 中设置 Webhook

目前这仅适用于 Discord 的公共测试构建,可以在以下位置找到:这里为 Windows这里为 Mac

  1. 在您拥有的服务器上(或拥有“管理 Webhooks”权限),打开服务器设置,然后在菜单中选择“Webhooks”: 步骤 2

  2. 点击“创建 Webhook”按钮并填写表格。您设置的“名称”字段和头像是默认值,可以在本封装器中覆盖,但 选择的渠道不能通过封装器更改。 您需要为每个要发布的渠道设置一个单独的 URL。 步骤 2

  3. 复制“Webhook URL”,并在初始化类时使用它。

  4. 享受吧!

示例

<?php
    include __DIR__.'/vendor/autoload.php';

    use \DiscordWebhooks\Client as DiscordWebhook;
    
    $discord = new DiscordWebhook('URL-FROM-DISCORD');
    $discord->name('AuroraAri'); // Optionally, provide a name that the message will be sent from. If not set, uses the name set in Discord.
    $discord->avatar('http://i.imgur.com/RNYMCQp.png'); // Optionally, a URL for the user's avatar. If not set, uses the avatar set in Discord.
    $discord->message('Hi, Discord!'); // Optionally, set the message to be sent here. If not set, uses the message in $this->send().
    $discord->send('Hi again, Discord!'); // If the message wasn't set in $this->message, it must be set here. This method sends the message.