Send image along with text to Discord using Webhooks

I'm trying to make a script that sends news, updates, to a server of Discord , for this I need to use the system of Webhooks. I've set up the whole system, including it's all working.

But the system I made only sends text, and I would like to make this system to also send along with the text, two images, to get a nice layout for the news.

In PHP I am using the following code to send messages to discord:

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

Except that this way only sends text. Getting like this there in discord:

insert the description of the image here

But I wanted the news to look like this:

insert the description of the image here

Can you understand me? I want to send these images from the top and footer along with the text, so that the news appears with a more beautiful look.


For you to better understand how the system works, add the Test server that creates in discord and the site that sends the news to discord:

Discord: https://discord.gg/6nGdjnz Posting Site: http://diegodevphp.esy.es /

Author: rray, 2017-11-11

1 answers

There are several ways to do what you want using CURL , one of them is:

$data = array("content" => $message, "username" => "News", "file" => "ENDERECO_DA_IMAGEM/IMAGEM.jpeg");
// Se sua versão do PHP for igual ou acima de 5.6.0
// a linha abaixo é necessária
curl_setopt($curl, CURLOPT_SAFE_UPLOAD, false);
 1
Author: NoobSaibot, 2017-11-13 11:45:38