

{"id":1352,"date":"2022-05-07T00:41:35","date_gmt":"2022-05-06T22:41:35","guid":{"rendered":"https:\/\/dornisoft.es\/dorniblog\/?p=1352"},"modified":"2022-05-07T00:42:54","modified_gmt":"2022-05-06T22:42:54","slug":"usar-los-web-hooks-de-discord-desde-php","status":"publish","type":"post","link":"https:\/\/dornisoft.es\/dorniblog\/usar-los-web-hooks-de-discord-desde-php\/","title":{"rendered":"Usar los web-hooks de Discord desde PHP"},"content":{"rendered":"\n<p>Para enviar mensajes a Discord desde PHP debemos crear un web-hook desde Discord.<br>Debemos ir a ajustes de nuestro servidor &gt; Integraciones y crear el web-hook , deberemos seleccionar el nombre y el canal donde se mostraran los mensajes y copiar la URL que nos facilita.<br><br>En nuestro servidor web ( hemos usado xampp) escribimos el siguiente script PHP:<br><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\/\/API URL\n$url = 'URL-QUE-HEMOS-COPIADO-ANTES';\n\n\/\/create a new cURL resource\n$ch = curl_init($url);\n\n\/\/setup request to send json via POST\n$data = array(\n    'content' => 'Hello DorniSoft!!'\n    \/\/'embeds' => '123456'\n);\n$payload = json_encode($data);\n\nprint_r($payload);\n\n\/\/attach encoded JSON string to the POST fields\ncurl_setopt($ch, CURLOPT_POSTFIELDS, $payload);\n\n\/\/set the content type to application\/json\ncurl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application\/json'));\n\n\/\/return response instead of outputting\ncurl_setopt($ch, CURLOPT_RETURNTRANSFER, true);\n\n\/\/execute the POST request\n$result = curl_exec($ch);\n\nprint $result;\n\n\/\/close cURL resource\ncurl_close($ch);\n\n?><\/pre>\n\n\n\n<p>V\u00e9ase que la variable $data es un array con los parametros que le pasamos a Discord y el elemento &#8216;content&#8217; es el mensaje que queremos enviar al canal .<br>Luego realizamos una petici\u00f3n POST a Discord enviandole el JSON y el mensaje se recibe en el canal seleccionado .<br><br><\/p>\n\n\n\n<p>Espero que te haya gustado \ud83d\ude09<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Para enviar mensajes a Discord desde PHP debemos crear un web-hook desde Discord.Debemos ir a ajustes de nuestro servidor &gt; Integraciones y crear el web-hook , deberemos seleccionar el nombre y el canal donde se mostraran los mensajes y copiar la URL que nos facilita. En nuestro servidor web ( hemos usado xampp) escribimos el &hellip; <a href=\"https:\/\/dornisoft.es\/dorniblog\/usar-los-web-hooks-de-discord-desde-php\/\" class=\"more-link\">Continuar leyendo<span class=\"screen-reader-text\"> \u00abUsar los web-hooks de Discord desde PHP\u00bb<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[29],"tags":[],"class_list":["post-1352","post","type-post","status-publish","format-standard","hentry","category-programacion"],"_links":{"self":[{"href":"https:\/\/dornisoft.es\/dorniblog\/wp-json\/wp\/v2\/posts\/1352","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/dornisoft.es\/dorniblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/dornisoft.es\/dorniblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/dornisoft.es\/dorniblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/dornisoft.es\/dorniblog\/wp-json\/wp\/v2\/comments?post=1352"}],"version-history":[{"count":2,"href":"https:\/\/dornisoft.es\/dorniblog\/wp-json\/wp\/v2\/posts\/1352\/revisions"}],"predecessor-version":[{"id":1354,"href":"https:\/\/dornisoft.es\/dorniblog\/wp-json\/wp\/v2\/posts\/1352\/revisions\/1354"}],"wp:attachment":[{"href":"https:\/\/dornisoft.es\/dorniblog\/wp-json\/wp\/v2\/media?parent=1352"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/dornisoft.es\/dorniblog\/wp-json\/wp\/v2\/categories?post=1352"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/dornisoft.es\/dorniblog\/wp-json\/wp\/v2\/tags?post=1352"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}