Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 响应聊天命令(webhooks)_Php_Webhooks_Discord - Fatal编程技术网

Php 响应聊天命令(webhooks)

Php 响应聊天命令(webhooks),php,webhooks,discord,Php,Webhooks,Discord,因此,我在discord上有一个非常简单的机器人设置: <?php function postToDiscord($message) { $data = array( "content" => $message, "username" => "myBot", ); $curl = curl_init("https://discordapp.com/api/webhooks/MY_HOOK"); curl_seto

因此,我在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");

Discord Webhook只能发布它们无法获取的内容

您的示例是指单向通信通道。您可以发布到该URL(正如您已经做的那样),只需将消息发送到该频道。为了真正阅读信息,你必须仔细阅读。你也许可以深入了解如何利用它。这应该和在
discordapp.com/api/channels/{channel.id}/messages
上执行
GET
一样简单。但可能需要实现一个bot(因此它充当虚拟用户)