对聊天命令做出反应(webhooks)

React to chat-commands (webhooks)

所以我有一个非常简单的 discord 机器人设置:

<?php

function postToDiscord($message)
{
    $data = array(
        "content" => $message,
        "username" => "myBot",
    );
    $curl = curl_init("https://discordapp.com/api/webhooks/MY_HOOK");
    curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($data));
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
    return curl_exec($curl);
}

postToDiscord("foo bar");

这按预期工作,但我不明白这些挂钩的概念。我在这里看到 an example 和 github,但这对 github 的操作有反应。就像,在提交之后,我可以触发一个 webhook 和 post 到一个频道。

但是,我想对 !song 等特定聊天命令做出反应,以从 spotify 检索当前歌曲。例如,在 twitch 上,我知道你可以从 IRC 中获取当前文本,但这对 discord 有何作用?

我想我需要一个观察者,它对给定的输入做出反应(也许是 ajax-调用?)。非常感谢任何想法或反馈。

Discord WebHooks 只能Post它们不能获取