m0by_cze/dmdiscordmsg

发送 Discord 消息的小类

1.0.1 2018-08-04 12:12 UTC

This package is auto-updated.

Last update: 2024-09-23 05:51:11 UTC


README

非常简单的代码,用于向 Discord 频道发送单个消息。

此代码最初是为了发送关于将我的项目部署到生产环境的服务消息而编写的。

如何使用

Composer

执行

$ composer require agorlov/discordmsg

创建 example.php

<?php

use AG\DiscordMsg;

require_once './vendor/autoload.php';

(new DiscordMsg('Greetings!'))->send();

运行它

$ php example.php

检查 Discord 频道(用于测试),你的消息已发送

https://discord.gg/jB5FsPf

经典的 require_once

  1. 将 Msg.php 和 DiscordMsg.php 放入您的项目中

  2. 查看其工作原理

example.php

require_once 'Msg.php';
require_once 'DiscordMsg.php';


echo "To see dumb messages..\n";
echo "..join the discordmsg chanel https://discord.gg/Bh4EZB and enjoy!\n";
echo "Feel free to test!\n";


// First message
$msg = new \AG\DiscordMsg('Hello, Friends');
$msg->send();


// Second message
(new \AG\DiscordMsg(
    'I started the example.php, something happened?',
    null,
    $_ENV["USER"] ?? 'Mr. Pitkin'
))->send();


// Third message
(new \AG\DiscordMsg(
    "Maybe the missile is launched? :grimacing:", // message
    'https://discordapp.com/api/webhooks/475239272610398218/' . // chanel webhook link
        'tfpeg5EFI_94oEHfltZwcB5UAurfcswkBw5mKouZCq-akhvxe5BNOtN16AqSHvmSwpum',
    get_current_user(), // bot name
    '' // avatar url
))->send();


```bash
$ php example.php

如何通知用户

感谢 @bricecarbou (agorlov#3)

要通过 webhook 通知任何人,我们需要使用用户的“真实”ID(在 Discord 中使用 @ 恢复),并使用 $msg="<@id_recovered> ...

$msg = "<@4386638385456546554> is notified";
(new \AG\DiscordMsg(
  $msg, // message
  $webhookurl, // chanel webhook link
  "Trad Bot", // bot name
  '' // avatar url
))->send();

如何获取 Webhook 链接

打开频道设置(如果您有足够的权限): image

创建 Webhook: image