agorlov/discordmsg

一个用于发送Discord消息的小类

1.0.1 2018-08-04 12:12 UTC

This package is auto-updated.

Last update: 2024-09-14 03:53:53 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 (#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