Advertisement
NubeColectiva

Como Publicar Desde Laravel a Discord (PHP Puro)

May 11th, 2022
1,744
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.13 KB | None | 0 0
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6.  
  7. class EnviarDiscordController extends Controller
  8. {
  9.    
  10.     public function enviar() {
  11.  
  12.         $registro = "Torta de Chocolate";
  13.  
  14.         $url_webhook = "TU-WEBHOOK-URL-DISCORD";
  15.  
  16.         $fechayhora = date("c", strtotime("now"));
  17.  
  18.         $datos_json = json_encode(
  19.             [
  20.                 "content" => "Esto es un Contenido",
  21.  
  22.                 "username" => "Nube Colectiva",
  23.  
  24.                 "avatar_url" => "https://nubecolectiva.com/img/logo.png",
  25.  
  26.                 "embeds" => [
  27.  
  28.                     [
  29.  
  30.                         "title" => $registro,
  31.  
  32.                         "type" => "rich",
  33.  
  34.                         "description" => "Esta es una descripción",
  35.  
  36.                         "url" => "https://nubecolectiva.com/",
  37.  
  38.                         "timestamp" => $fechayhora,
  39.  
  40.                         "thumbnail" => [
  41.                             "url" => "https://blog.nubecolectiva.com/wp-content/uploads/2022/03/edit_jimg_destacada_blog_devs-530x353.png"
  42.                         ],
  43.  
  44.                         "image" => [
  45.                             "url" => "https://blog.nubecolectiva.com/wp-content/uploads/2022/03/edit_jimg_destacada_blog_devs-530x353.png"
  46.                         ],
  47.  
  48.                         "author" => [
  49.  
  50.                             "name" => "Nube Colectiva",
  51.                             "url" => "https://nubecolectiva.com/"
  52.  
  53.                         ]
  54.  
  55.                     ]
  56.  
  57.  
  58.                 ]
  59.  
  60.  
  61.             ], JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE );
  62.  
  63.  
  64.             $curl = curl_init($url_webhook);
  65.             curl_setopt( $curl, CURLOPT_HTTPHEADER, array('Content-type: application/json'));
  66.             curl_setopt( $curl, CURLOPT_POST, 1);
  67.             curl_setopt( $curl, CURLOPT_POSTFIELDS, $datos_json);
  68.             curl_setopt( $curl, CURLOPT_FOLLOWLOCATION, 1);
  69.             curl_setopt( $curl, CURLOPT_HEADER, 0);
  70.             curl_setopt( $curl, CURLOPT_RETURNTRANSFER, 1);      
  71.  
  72.             $respuesta = curl_exec($curl);
  73.  
  74.             curl_close($curl);
  75.  
  76.  
  77.     }
  78.  
  79. }
  80.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement