antiblock
diamwall
  • Chatbox

    Did you check out our Discord? https://discord.gg/FFdvMjk9xA
    You don't have permission to chat.
    Load More
Papix

[PHP] Discord automatic messages (CRON)(WEBHOOK)

1 post in this topic

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:
.png


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

  1.  Altera o fuso horário em date_default_timezone_set com o teu fuso horário (linha 4)
  2.  Substituir WEBHOOK_HERE pelo teu URL de webhook (Linha 9)
  3.  Substitui KEY_HERE pela chave aleatória (linha 64)
  4.  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.

 

.png

Share this post


Link to post
Share on other sites
antiblock
https://arwen2.global/

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now