drmongrel/discord-webhooks-php

auroraari 的 discord webhooks 为 PHP 定制的库。

安装: 8

依赖项: 0

建议者: 0

安全性: 0

类型:包装器

dev-master 2018-02-25 17:22 UTC

This package is not auto-updated.

Last update: 2024-09-24 18:32:30 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.