Discord

A library for sending messages and files to Discord channels via webhooks.


type TDiscordEmbed

TDiscordEmbed = record
  Title: String;
  Description: String;
  Color: Int32;
  Footer: String;
  ImageURL: String;
  ThumbnailURL: String;
end;

Represents a Discord embed object that can be attached to messages.


type TDiscordWebhook

TDiscordWebhook = record
  URL: String;
  Username: String;
  AvatarURL: String;
  Content: String;
  Embeds: array of TDiscordEmbed;
end;

Represents a Discord webhook configuration with content and embeds.


type TDiscordClient

TDiscordClient = record(TSRLBaseRecord)
  Webhook: TDiscordWebhook;
  Config: TConfigJSON;
  HTTP: Int32;
  LastResponse: String;
  LastError: String;
  RetryCount: Int32;
  RetryDelay: Int32;
  ScreenshotPath: String;
end;

Main client for interacting with Discord webhooks.


TDiscordWebhook.Setup

procedure TDiscordWebhook.Setup(URL: String);

Setup a webhook with the given URL.

Example:

MyWebhook.Setup('https://discord.com/api/webhooks/your_webhook_id/your_webhook_token');

TDiscordWebhook.AddEmbed

function TDiscordWebhook.AddEmbed: Int32;

Adds a new embed to the webhook and returns its index.

Example:

EmbedIdx := MyWebhook.AddEmbed();
MyWebhook.Embeds[EmbedIdx].Title := 'Status Report';

TDiscordWebhook.ClearEmbeds

procedure TDiscordWebhook.ClearEmbeds;

Removes all embeds from the webhook.


TDiscordWebhook.ClearAll

procedure TDiscordWebhook.ClearAll;

Clears both content and embeds from the webhook.


TDiscordWebhook.ToJSON

function TDiscordWebhook.ToJSON: String;

Converts the webhook to a JSON string for API requests.


TDiscordClient.Setup

procedure TDiscordClient.Setup(ConfigPath: String = '');

Setup the Discord client from a configuration file.

Example:

MyDiscord.Setup(); // Uses default 'discord.json'
MyDiscord.Setup('my_config.json'); // Uses specified file

TDiscordClient.SetWebhook

function TDiscordClient.SetWebhook(WebhookURL: String): Boolean;

Sets the webhook URL for the Discord client.

Example:

MyDiscord.SetWebhook('https://discord.com/api/webhooks/your_webhook_id/your_webhook_token');

TDiscordClient.SetUsername

procedure TDiscordClient.SetUsername(Username: String);

Sets the username that appears for webhook messages.

Example:

MyDiscord.SetUsername('OSRS Bot');

TDiscordClient.SetAvatar

procedure TDiscordClient.SetAvatar(AvatarURL: String);

Sets the avatar image URL for webhook messages.

Example:

MyDiscord.SetAvatar('https://example.com/avatar.png');

TDiscordClient.Send

function TDiscordClient.Send: Boolean;

Sends the current webhook content and embeds to Discord.

Example:

MyDiscord.Webhook.Content := 'Hello from Simba!';
if MyDiscord.Send() then
  WriteLn('Message sent successfully');

TDiscordClient.SendFile

function TDiscordClient.SendFile(FilePath: String): Boolean;

Sends a file to the Discord channel.

Example:

if MyDiscord.SendFile('C:\path\to\image.png') then
  WriteLn('File sent successfully');

TDiscordClient.SendScreenshot

function TDiscordClient.SendScreenshot(Anonymous: Boolean = True): Boolean;

Takes a screenshot of the client and sends it to Discord. When Anonymous is True, account-identifying information is hidden.

Example:

if MyDiscord.SendScreenshot(True) then
  WriteLn('Screenshot sent successfully');

TDiscordClient.MentionUser

function TDiscordClient.MentionUser(UserID: String): String;

Returns a formatted mention for a Discord user.

Example:

Discord.Webhook.Content := 'Alert! ' + Discord.MentionUser('123456789012345678');

TDiscordClient.Free

procedure TDiscordClient.Free;

Cleans up resources used by the Discord client.