Upload Image along with text to Discord Using Webhooks

2

I'm trying to make a script that sends news, updates, to a Discord server, so I need to use the Webhooks system. I already mounted the whole system, everything is already working.

But the system I just sent text, and I would like to make this system to also send along with the text, two images, to get a very cool layout for the news.

In PHP I'm using the following code to send the messages to the 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);
}
?>

Only this way, it only sends text. Staying there in the discord:

ButIwantedthenewstolooklikethis:

Canyouunderstandme?Iwanttosendthesetopandfooterimagesalongwiththetext,sothenewswillappearmorebeautiful.

Forabetterunderstandingofhowthesystemworks,addtheTestServeryoucreateinthediscordandthesitethatsendsthenewstothediscord:

discord: link Posting site: link

    
asked by anonymous 11.11.2017 / 17:58

1 answer

1

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);
    
13.11.2017 / 12:45