samp.directory
← Скрипты и библиотеки

dev-ortex/DiscordWebHook-Samp

На GitHub нет описания.

Библиотека★ 1обновлён июль 2026 г.Без лицензииPawn
Открыть на GitHub

В этом репозитории нет файла лицензии. Код открыт для чтения, но само по себе это не даёт права использовать его.

README.md

🔗 Discord Webhook

A Pawn include for connecting your SA-MP/Open.MP server to Discord using webhooks. Ideal for server logs, admin actions, ban logs, connection logs, automated messages, and custom Discord embeds.


📦 Installation

  1. Download the latest version of discord_webhook.inc.
  2. Place the file inside your server’s include/ folder.
  3. Install the required dependency:
sampctl package install Southclaws/pawn-requests
  1. Add the plugin to your server.

For server.cfg:

plugins requests

For Open.MP config.json:

{
    "pawn": {
        "legacy_plugins": [
            "requests"
        ]
    }
}
  1. Include it in your gamemode or filterscript:
#include <discord_webhook>

⚙️ Functions

stock DiscordHook_Create(const hookname[], const webhook_url[]);
stock DiscordHook_Find(const hookname[]);

stock Discord_SendMessage(const hookname[], const message[], const callback[] = "");

stock DiscordEmbed_Clear();

stock DiscordEmbed_SetTitle(const title[]);
stock DiscordEmbed_SetDescription(const description[]);
stock DiscordEmbed_SetColor(color);

stock DiscordEmbed_SetAuthor(const name[], const url[], const icon_url[]);
stock DiscordEmbed_SetThumbnail(const url[]);
stock DiscordEmbed_SetImage(const url[]);
stock DiscordEmbed_SetFooter(const text[], const icon_url[]);

stock Discord_AddField(const name[], const value[], bool:inline = false);

stock DiscordEmbed_Send(const hookname[], const callback[] = "");

[!IMPORTANT]

  • hookname: Internal name used to identify a registered webhook.
  • webhook_url: Discord webhook URL from your Discord channel.
  • callback: Optional request callback used to handle HTTP responses.
  • inline: Defines whether the embed field should appear side by side with other fields.
  • Always call DiscordEmbed_Clear() before creating a new embed.

🧠 Embed Properties

FunctionDescription
DiscordEmbed_SetTitleSets the embed title
DiscordEmbed_SetDescriptionSets the embed description
DiscordEmbed_SetColorSets the embed side color
DiscordEmbed_SetAuthorSets the embed author name, URL, and icon
DiscordEmbed_SetThumbnailSets the small image on the top-right
DiscordEmbed_SetImageSets the main embed image
Discord_AddFieldAdds a field to the embed
DiscordEmbed_SetFooterSets the embed footer text and icon
DiscordEmbed_SendSends the current embed to Discord

🧪 Example Usage

public OnGameModeInit()
{
    DiscordHook_Create(
        "logs",
        "https://discord.com/api/webhooks/YOUR_WEBHOOK_URL"
    );

    Discord_SendMessage("logs", "✅ Server started successfully!");
    return 1;
}

🧩 Complete Embed Example

CMD:testembed(playerid)
{
    DiscordEmbed_Clear();

    DiscordEmbed_SetTitle("🚀 Complete Embed Test");
    DiscordEmbed_SetDescription("This embed was sent from a SA-MP/Open.MP server using Discord Webhook.");
    DiscordEmbed_SetColor(0x3498DB);

    DiscordEmbed_SetAuthor(
        "Server Roleplay",
        "https://discord.gg/yourserver",
        "https://i.imgur.com/example.png"
    );

    DiscordEmbed_SetThumbnail("https://i.imgur.com/example.png");
    DiscordEmbed_SetImage("https://i.imgur.com/example.png");

    Discord_AddField("Server", "Server Roleplay", true);
    Discord_AddField("Status", "Online", true);
    Discord_AddField("Players", "15/100", true);
    Discord_AddField("Version", "0.1 Beta", true);
    Discord_AddField("Message", "The Discord log system is working correctly.", false);

    DiscordEmbed_SetFooter(
        "Log System • Server Roleplay",
        "https://i.imgur.com/example.png"
    );

    DiscordEmbed_Send("logs", "OnDiscordResponse");

    SendClientMessage(playerid, -1, "[Discord] Embed sent successfully.");
    return 1;
}

forward OnDiscordResponse(Request:id, E_HTTP_STATUS:status, Node:node);
public OnDiscordResponse(Request:id, E_HTTP_STATUS:status, Node:node)
{
    if(Discord_Success(status))
        return printf("[Discord] Embed sent successfully. Status: %d", _:status);
    
    printf("[Discord] Failed to send embed. Status: %d", _:status);
    return 1;
}

📝 Ban Log Example

stock Discord_LogBan(playerid, adminid, const reason[])
{
    new playerName[MAX_PLAYER_NAME];
    new adminName[MAX_PLAYER_NAME];

    GetPlayerName(playerid, playerName, sizeof(playerName));
    GetPlayerName(adminid, adminName, sizeof(adminName));

    DiscordEmbed_Clear();

    DiscordEmbed_SetTitle("🚨 Ban Log");
    DiscordEmbed_SetDescription("A player has been banned from the server.");
    DiscordEmbed_SetColor(0xFF0000);

    Discord_AddField("Player", playerName, true);
    Discord_AddField("Admin", adminName, true);
    Discord_AddField("Reason", reason, false);

    DiscordEmbed_SetFooter("Administrative System", "");

    DiscordEmbed_Send("logs");

    return 1;
}

⚠️ Notes

[!WARNING]

Never expose your Discord webhook URL in public repositories.

Anyone with your webhook URL can send messages to your Discord channel. If your webhook URL is leaked, delete it from Discord and create a new one.


📷 Photo Video

https://github.com/user-attachments/assets/f2e69247-5c85-449b-88d9-ae2392ca3c20


🙌 Credits

  • Ortex – Original author and developer of the include.

🌐 Other Languages

Страница собрана из того, что GitHub публикует о репозитории. samp.directory не хранит этот код. Сообщить о проблеме с этой записью

dev-ortex/DiscordWebHook-Samp: Библиотека для SA-MP | samp.directory