Skip to content
This repository has been archived by the owner on Dec 23, 2020. It is now read-only.

haxtonsale/SMDiscordWebhook.inc

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SMDiscordWebhook.inc

.inc that sends messages and embeds through discord webhooks in SourceMod for you.

Requirements

Requires SteamWorks or SteamTools.
sm-json is required for DiscordWebhook_ExecuteJson.

Sending messages

#include <sourcemod>
#include <SteamWorks>
#include <discordwebhook>

public int SteamWorks_SteamServersConnected()
{
    DiscordWebhook_Execute(WebhookId, WebhookToken, "Test message!", OnDWResponseReceived);
}

void OnDWResponseReceived(int code, char[] webhookId, DWRateLimits rateLimits)
{
    if (code >= 400)
    {
        char err[256];
        DiscordWebhook_GetErrorMsg(err, sizeof(err));
        LogError("SMDiscordWebhook HTML Error %i: %s", code, err);
    }
    else
    {
        PrintToServer("(%s): Limit %i; Remaining %i; Reset %i", webhookId, rateLimits.Limit, rateLimits.Remaining, rateLimits.Reset);
    }
}

Sending a JSON body using DiscordWebhook_ExecuteRaw

#include <sourcemod>
#include <SteamWorks>
#include <discordwebhook>

public int SteamWorks_SteamServersConnected()
{
    char body[] = "{\"content\": \"Test message!\", \"embeds\": [{\"title\": \"Embed\"}]}";
    DiscordWebhook_ExecuteRaw(WebhookId, WebhookToken, "application/json", body);
}

Sending a message using DiscordWebhook_ExecuteJson (Requires sm-json)

#include <sourcemod>
#include <SteamWorks>
#include <json>
#include <discordwebhook>

public int SteamWorks_SteamServersConnected()
{
    RichEmbed embed = new RichEmbed();
    embed.SetTitle("Embed Title");
    embed.SetColor(0x6E14FF);
    embed.SetFooter("Footer");
    embed.SetImage("https://sun9-56.userapi.com/c543105/v543105102/6f1ba/HvB5HmGHPCc.jpg");
    embed.SetAuthor("Author");
    embed.AddField("Field 1", "Text", true);
    embed.AddField("Field 2", "More text", true);
    
    JSON_Array embeds = new JSON_Array();
    embeds.PushObject(embed);
    
    DiscordWebhook_ExecuteJson(WebhookId, WebhookToken, "Test message!", .embeds = embeds);
    
    embeds.Cleanup();
    delete embeds;
}

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published