.inc that sends messages and embeds through discord webhooks in SourceMod for you.
Requires SteamWorks or SteamTools.
sm-json is required for DiscordWebhook_ExecuteJson
.
#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);
}
}
#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);
}
#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;
}