curl – Send private message using PHP (userbot)

Basically i am trying to use php and curl to send messages as user.

It’s working half-ish, basically i have gotten it to send a message but whenever i refresh the php again to try to make it send again it doesn’t wanna send again…. and i have no clue why since i don’t understand the discord api that well.

Anyways, here’s my function for sending message:

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, "$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:$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);
return $output;

And heres what im executing with the function file included:

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

If anyone is more experienced with the discord api and can clarify on this, would be grateful.