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
2) Creating a Discord webhook
3) Send message from server
Now when a player connect to the server, a message will be sent on the discord channel.
Credits
Southclaws for the requests package
Regards
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 :
- Pawn-requests package
- Discord server
1) Install pawn-requests package on your server
- Install the package with sampctl or manually
2) Creating a Discord webhook
- Create text channel
- Click "Edit Channel" => Integrations => Create Webhook
- Click on the Webhook => Copy Webhook url (save it for later)
3) Send message from server
- 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");
}
- 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.
Credits
Southclaws for the requests package
Regards