open.mp forum
Sending message to Discord - Printable Version

+- open.mp forum (https://forum.open.mp)
+-- Forum: SA-MP (https://forum.open.mp/forumdisplay.php?fid=3)
+--- Forum: Tutorials (https://forum.open.mp/forumdisplay.php?fid=37)
+--- Thread: Sending message to Discord (/showthread.php?tid=2354)



Sending message to Discord - Kox - 2023-02-19

Hi,

This tutorial aims to give you a basic example about how to use a webhook to send message from your OpenMP/SA-MP server into a discord channel.

Requirements :

1) Install pawn-requests package on your server
  • Install the package with sampctl or manually

2) Creating a Discord webhook
  1. Create text channel
  2. Click "Edit Channel" =>  Integrations => Create Webhook
  3. Click on the Webhook => Copy Webhook url (save it for later)

3) Send message from server
  1. Add requests include and create a RequestsClient with your webhook url
    PHP Code:
    #include <requests> new RequestsClient:client; main() {     client = RequestsClient("replace with your webhookurl"); }

  2. Send message to discrod
    PHP Code:
    public OnPlayerConnect(playerid) {     new name[MAX_PLAYER_NAME + 1];     GetPlayerName(playerid, name, sizeof(name));     new string[MAX_PLAYER_NAME + 23 + 1];     format(string, sizeof(string), "%s has joined the server.", name);     RequestJSON(         client,         "",                    HTTP_METHOD_POST,         "OnPostJson",            JsonObject(             "content", JsonString(string)         )     );     return 1; } forward OnPostJson(Request:id, E_HTTP_STATUS:status, Node:node); public OnPostJson(Request:id, E_HTTP_STATUS:status, Node:node) {     if(status == HTTP_STATUS_NO_CONTENT) {         printf("successfully posted message");     }     else     {         printf("failed to post message");     } }

Now when a player connect to the server, a message will be sent on the discord channel.

[Image: webhook-discord.png]

Credits
Southclaws for the requests package


Regards


RE: Sending message to Discord - Torque - 2025-01-09

Disregard.


RE: Sending message to Discord - siwode - 2025-01-11

nice!