使用 PHP (userbot) 发送私人消息

时间:2021-04-03 06:48:12

标签: php curl discord

我正在尝试使用 php 和 curl 以用户身份发送消息。

它的工作效率不高,基本上我已经得到它来发送消息,但是每当我再次刷新 php 以尝试使其再次发送时,它就不想再次发送,而且我不知道为什么,因为我不这样做不太了解 discord API。

无论如何,这是我发送消息的功能:

function sendChannelMessage ($channel, $msg) {
$sessions = file("bot.txt", FILE_SKIP_EMPTY_LINES | FILE_IGNORE_NEW_LINES);
foreach ($sessions as $session) {
$tag = explode("|", $session);
$authtoken = $tag[1];
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, "https://discordapp.com/api/v6/channels/$channel/messages");
curl_setopt($curl, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0');
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$headers = array();
$headers[] = "Connection: keep-alive";
$headers[] = "User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:53.0) Gecko/20100101 Firefox/53.0";
$headers[] = "Content-Type: application/json;charset=utf-8";
$headers[] = "Referer: https://discordapp.com/channels/$channel/";
$headers[] = "Authorization: $authtoken";
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($curl, CURLOPT_POST, 1);
$requ3st = array("content" => $msg, "nonce" => $channel);
$requ3st_encoded = json_encode($requ3st);
curl_setopt($curl, CURLOPT_POSTFIELDS, $requ3st_encoded);
$output = curl_exec($curl);
curl_close($curl);
return $output;
}
}

这是我在包含函数文件的情况下执行的操作:

include 'runme.php';
$c = "channel_id";
echo sendChannelMessage($c, "TEST");

编辑

  • 好像我每 4-5 分钟只能发送 1 条消息?
  • 有什么办法可以绕过这个,因为它是一个用户令牌,不应该受到限制?

0 个答案:

没有答案
相关问题