php discord post

Solutions on MaxInterview for php discord post by the best coders in the world

showing results for - "php discord post"
Juan Pablo
07 Oct 2018
1<?php
2//2021 current working model
3$url = "https://discordapp.com/api/webhooks/0000000/ABCDEFGH....";
4
5$hookObject = json_encode([
6    /*
7     * The general "message" shown above your embeds
8     */
9    "content" => "A message will go here",
10    /*
11     * The username shown in the message
12     */
13    "username" => "MyUsername",
14    /*
15     * The image location for the senders image
16     */
17    "avatar_url" => "https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg",
18    /*
19     * Whether or not to read the message in Text-to-speech
20     */
21    "tts" => false,
22    /*
23     * File contents to send to upload a file
24     */
25    // "file" => "",
26    /*
27     * An array of Embeds
28     */
29    "embeds" => [
30        /*
31         * Our first embed
32         */
33        [
34            // Set the title for your embed
35            "title" => "Google.com",
36            
37            // The type of your embed, will ALWAYS be "rich"
38            "type" => "rich",
39            
40            // A description for your embed
41            "description" => "",
42            
43            // The URL of where your title will be a link to
44            "url" => "https://www.google.com/",
45            
46            /* A timestamp to be displayed below the embed, IE for when an an article was posted
47             * This must be formatted as ISO8601
48             */
49            "timestamp" => "2018-03-10T19:15:45-05:00",
50            
51            // The integer color to be used on the left side of the embed
52            "color" => hexdec( "FFFFFF" ),
53            
54            // Footer object
55            "footer" => [
56                "text" => "Google TM",
57                "icon_url" => "https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg"
58            ],
59            
60            // Image object
61            "image" => [
62                "url" => "https://www.google.com/images/branding/googlelogo/1x/googlelogo_color_272x92dp.png"
63            ],
64            
65            // Thumbnail object
66            "thumbnail" => [
67                "url" => "https://pbs.twimg.com/profile_images/972154872261853184/RnOg6UyU_400x400.jpg"
68            ],
69            
70            // Author object
71            "author" => [
72                "name" => "Alphabet",
73                "url" => "https://www.abc.xyz"
74            ],
75            
76            // Field array of objects
77            "fields" => [
78                // Field 1
79                [
80                    "name" => "Data A",
81                    "value" => "Value A",
82                    "inline" => false
83                ],
84                // Field 2
85                [
86                    "name" => "Data B",
87                    "value" => "Value B",
88                    "inline" => true
89                ],
90                // Field 3
91                [
92                    "name" => "Data C",
93                    "value" => "Value C",
94                    "inline" => true
95                ]
96            ]
97        ]
98    ]
99    
100], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
101
102$headers = [ 'Content-Type: application/json; charset=utf-8' ];
103$POST = [ 'username' => 'Testing BOT', 'content' => 'Testing message' ];
104
105$ch = curl_init();
106curl_setopt($ch, CURLOPT_URL, $url);
107curl_setopt($ch, CURLOPT_POST, true);
108curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
109curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
110curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
111curl_setopt($ch, CURLOPT_POSTFIELDS, $hookObject);
112$response   = curl_exec($ch);