• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sending message to Discord
#1
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
  Reply


Messages In This Thread
Sending message to Discord - by Kox - 2023-02-19, 12:35 PM
RE: Sending message to Discord - by Torque - 2025-01-09, 10:24 PM
RE: Sending message to Discord - by siwode - 2025-01-11, 05:38 PM