# Discord A library for sending messages and files to Discord channels via webhooks. - - - (TDiscordEmbed)= ## type TDiscordEmbed ```pascal 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. - - - (TDiscordWebhook)= ## type TDiscordWebhook ```pascal TDiscordWebhook = record URL: String; Username: String; AvatarURL: String; Content: String; Embeds: array of TDiscordEmbed; end; ``` Represents a Discord webhook configuration with content and embeds. - - - (TDiscordClient)= ## type TDiscordClient ```pascal 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 ```pascal procedure TDiscordWebhook.Setup(URL: String); ``` Setup a webhook with the given URL. Example: ```pascal MyWebhook.Setup('https://discord.com/api/webhooks/your_webhook_id/your_webhook_token'); ``` - - - ## TDiscordWebhook.AddEmbed ```pascal function TDiscordWebhook.AddEmbed: Int32; ``` Adds a new embed to the webhook and returns its index. Example: ```pascal EmbedIdx := MyWebhook.AddEmbed(); MyWebhook.Embeds[EmbedIdx].Title := 'Status Report'; ``` - - - ## TDiscordWebhook.ClearEmbeds ```pascal procedure TDiscordWebhook.ClearEmbeds; ``` Removes all embeds from the webhook. - - - ## TDiscordWebhook.ClearAll ```pascal procedure TDiscordWebhook.ClearAll; ``` Clears both content and embeds from the webhook. - - - ## TDiscordWebhook.ToJSON ```pascal function TDiscordWebhook.ToJSON: String; ``` Converts the webhook to a JSON string for API requests. - - - ## TDiscordClient.Setup ```pascal procedure TDiscordClient.Setup(ConfigPath: String = ''); ``` Setup the Discord client from a configuration file. Example: ```pascal MyDiscord.Setup(); // Uses default 'discord.json' MyDiscord.Setup('my_config.json'); // Uses specified file ``` - - - ## TDiscordClient.SetWebhook ```pascal function TDiscordClient.SetWebhook(WebhookURL: String): Boolean; ``` Sets the webhook URL for the Discord client. Example: ```pascal MyDiscord.SetWebhook('https://discord.com/api/webhooks/your_webhook_id/your_webhook_token'); ``` - - - ## TDiscordClient.SetUsername ```pascal procedure TDiscordClient.SetUsername(Username: String); ``` Sets the username that appears for webhook messages. Example: ```pascal MyDiscord.SetUsername('OSRS Bot'); ``` - - - ## TDiscordClient.SetAvatar ```pascal procedure TDiscordClient.SetAvatar(AvatarURL: String); ``` Sets the avatar image URL for webhook messages. Example: ```pascal MyDiscord.SetAvatar('https://example.com/avatar.png'); ``` - - - ## TDiscordClient.Send ```pascal function TDiscordClient.Send: Boolean; ``` Sends the current webhook content and embeds to Discord. Example: ```pascal MyDiscord.Webhook.Content := 'Hello from Simba!'; if MyDiscord.Send() then WriteLn('Message sent successfully'); ``` - - - ## TDiscordClient.SendFile ```pascal function TDiscordClient.SendFile(FilePath: String): Boolean; ``` Sends a file to the Discord channel. Example: ```pascal if MyDiscord.SendFile('C:\path\to\image.png') then WriteLn('File sent successfully'); ``` - - - ## TDiscordClient.SendScreenshot ```pascal 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: ```pascal if MyDiscord.SendScreenshot(True) then WriteLn('Screenshot sent successfully'); ``` - - - ## TDiscordClient.MentionUser ```pascal function TDiscordClient.MentionUser(UserID: String): String; ``` Returns a formatted mention for a Discord user. Example: ```pascal Discord.Webhook.Content := 'Alert! ' + Discord.MentionUser('123456789012345678'); ``` - - - ## TDiscordClient.Free ```pascal procedure TDiscordClient.Free; ``` Cleans up resources used by the Discord client.