Sending Discord Webhook with java

Viewed 141

I want something like this, but with a file attachment, so i can send an embed and under it the image. It doesnt have to like this exactly, but it should like something like this: enter image description here

   package com.StrgC;
    import java.io.OutputStream;
    import java.net.URL;
    
    import javax.net.ssl.HttpsURLConnection;
    
    public class WarningSending {
        public static void SendWarning() {
            ///////////////////////////////////////////////
            // CONFIG
    
            String tokenWebhook = "";
            String title = "";
            String message = "";
            ///////////////////////////////////////////////
            String jsonBrut = "";
            jsonBrut += "{\"embeds\": [{"
                    + "\"title\": \""+ title +"\","
                    + "\"description\": \""+ message +"\","
                    + "\"color\": 15925248"
                    + "}]}";
            try {
                URL url = new URL(tokenWebhook);
                HttpsURLConnection con = (HttpsURLConnection) url.openConnection();
                con.addRequestProperty("Content-Type", "application/json");
                con.addRequestProperty("User-Agent", "Java-DiscordWebhook-BY-Gelox_");
                con.setDoOutput(true);
                con.setRequestMethod("POST");
                OutputStream stream = con.getOutputStream();
                stream.write(jsonBrut.getBytes());
                stream.flush();
                stream.close();
                con.getInputStream().close();
                con.disconnect();
            } catch (Exception e) {
                e.printStackTrace()
            }
    
                }
    }
0 Answers
Related