0

It doesn't work and responds with

{"message": "Cannot send an empty message", "code": 50006}

I've tried entering the message into CURLOPT_POSTFIELDS

<?php
$url = 'https://discordapp.com/api/channels/638164827180630046/messages';

$ch = curl_init();
$payload = json_encode( array( "content"=> "a", "nonce"=> "638201106664521728", "tts"=> false ) );
curl_setopt_array($ch, array(
    CURLOPT_URL            => $url, 
    CURLOPT_HTTPHEADER     => array('Authorization: Bot <token>'), 
    CURLOPT_RETURNTRANSFER => 1,
    CURLOPT_FOLLOWLOCATION => 1,
    CURLOPT_VERBOSE        => 1,
    CURLOPT_SSL_VERIFYPEER => 0,
    CURLOPT_POSTFIELDS     => "a"
));
$response = curl_exec($ch);
fclose($f);
curl_close($ch);
echo $response;
?>

I want it to send a message

roan
  • 21
  • 1
  • 3
  • tried giving `CURLOPT_POSTFIELDS` param with non-array `$payload` like anobject? – Bagus Tesa Oct 28 '19 at 03:00
  • after sending a message it just reads them? is there any way to fix this? – roan Oct 28 '19 at 03:07
  • sorry, perhaps i'm a bit unclear, try sending a json object instead of array (e.g. `{"content":"a","nonce":"12131321231231231","tts":false}`), you can use [`stdClass`](https://stackoverflow.com/questions/931407/what-is-stdclass-in-php) to create arbitrary class, [simple example](https://pastebin.com/BZKw8BZX). – Bagus Tesa Oct 28 '19 at 03:14

0 Answers0