Papix 452 Posted November 4, 2023 Olá comunidade, Neste guia vou ensinar-vos uma forma simples de enviar mensagens automáticas usando apenas php, cron e webhook do discord. A função foi criada para anunciar eventos semanais, mas pode ser facilmente alterada para outros fins. A função está protegida por uma chave, pelo que se a chave não estiver definida o script não será executado. Preview: Script: <?php function Start() { date_default_timezone_set('Europe/Lisbon'); $data = date('d-m-Y'); $day = date('w', strtotime($data)); $url = "WEBHOOK_HERE"; $headers = [ 'Content-Type: application/json; charset=utf-8' ]; // Sunday if ($day == 0) { $POST = [ 'username' => 'TheBestPvP', 'content' => '• O evento **Caixa do Tesouro Hexagonal** começou! @here' ]; } // Monday if ($day == 1) { $POST = [ 'username' => 'TheBestPvP', 'content' => '• O evento **Caixa Tesouro do Luar** começou! @here' ]; } // Tuesday if ($day == 2) { $POST = [ 'username' => 'TheBestPvP', 'content' => '• O evento **Caixa do Tesouro Hexagonal** começou! @here' ]; } // Wednesday if ($day == 3) { $POST = [ 'username' => 'TheBestPvP', 'content' => '• O evento **Caixa do Tesouro Hexagonal** começou! @here' ]; } // Thursday if ($day == 4) { $POST = [ 'username' => 'TheBestPvP', 'content' => '• O evento **Ostra** começou! @here' ]; } // Friday if ($day == 5) { $POST = [ 'username' => 'TheBestPvP', 'content' => '• O evento **Super Boss** começou! @here' ]; } // Saturday if ($day == 6) { $POST = [ 'username' => 'TheBestPvP', 'content' => '• O evento **Caixa Tesouro do Luar** começou! @here' ]; } $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($POST)); $response = curl_exec($ch); } $key = "KEY_HERE"; if(!empty($_GET["key"])) { Start(); echo "Done"; } else { echo "Ups..."; } ?> Guide Altera o fuso horário em date_default_timezone_set com o teu fuso horário (linha 4) Substituir WEBHOOK_HERE pelo teu URL de webhook (Linha 9) Substitui KEY_HERE pela chave aleatória (linha 64) Altera as mensagens a seu gosto. Como executar? example.com/discord.php?key=KEY_HERE Como agendar o cron? Se não souberes como configurar 1 cron, pode utilizar o website: https://cron-job.org/ Só é necessário criar uma conta e criar o cron. 1 Big_Z reacted to this Share this post Link to post Share on other sites