Discord Gateway API

Connect to the Discord Gateway over WebSocket to build bots that react to messages, presence, guild and voice-state events in real time.

TsgcWSAPI_Discord

Typed Delphi/C++Builder client for the Discord Gateway WebSocket API — handles the heartbeat, identify, intents, sharding and event dispatch.

Component class

TsgcWSAPI_Discord

Protocol

Discord Gateway

Platforms

Windows, macOS, Linux, iOS, Android

Edition

Standard / Professional / Enterprise

Drop the component, set token, listen for events

Pair with TsgcWebSocketClient, set Discord.Token and Discord.Intents, then hook OnDiscordMessageCreate / OnDiscordReady to handle gateway events.

uses
  sgcWebSocket, sgcWebSocket_API_Discord;

var
  WSClient: TsgcWebSocketClient;
  Discord: TsgcWSAPI_Discord;
begin
  WSClient := TsgcWebSocketClient.Create(nil);

  Discord := TsgcWSAPI_Discord.Create(nil);
  Discord.Client := WSClient;
  Discord.Discord.Token := 'your-bot-token';

  Discord.OnDiscordReady := procedure(Connection: TsgcWSConnection;
    const aPayload: string)
  begin
    Memo1.Lines.Add('Discord ready');
  end;

  Discord.OnDiscordMessageCreate := procedure(Connection: TsgcWSConnection;
    const aMessage: string)
  begin
    Memo1.Lines.Add(aMessage);
  end;

  WSClient.Active := True;
end;
// uses: sgcWebSocket, sgcWebSocket_API_Discord
TsgcWebSocketClient *WSClient = new TsgcWebSocketClient(this);
TsgcWSAPI_Discord *Discord = new TsgcWSAPI_Discord(this);
Discord->Client = WSClient;
Discord->Discord->Token = "your-bot-token";

WSClient->Active = true;

What's inside

Implements the Discord Gateway protocol on top of TsgcWebSocketClient: IDENTIFY, RESUME, HEARTBEAT, dispatch routing.

Gateway handshake

On connect the component sends IDENTIFY with token, intents and properties; on disconnect it sends RESUME with the last sequence number so events are not lost.

Heartbeat

Discord requires opcode-1 HEARTBEAT messages on the interval the gateway returns in HELLO. The component schedules them and watches HEARTBEAT_ACK to detect zombied connections.

Intents

Discord.Intents selects which event categories the gateway delivers (GUILD_MESSAGES, GUILD_MEMBERS, MESSAGE_CONTENT, VOICE_STATES — full intent bitmask).

Event dispatch

Each gateway dispatch event surfaces as a typed property: OnDiscordReady, OnDiscordMessageCreate, OnDiscordGuildCreate, OnDiscordPresenceUpdate and many more.

Voice gateway hooks

Receive VOICE_STATE_UPDATE and VOICE_SERVER_UPDATE events — combine with the voice-WebSocket endpoint for voice channel automation.

Sharding-ready

Set Discord.Shard and Discord.ShardCount to participate in Discord's sharded gateway when your bot crosses the recommended guild threshold.

Specifications & references

Authoritative sources for the APIs this component implements.

Documentation & Demos

Deep-link to the component reference, grab the ready-to-run demo project, and download the trial.

Online Help — API_Discord Full property, method and event reference for this component.
Free Trial — sgcWebSockets Build your Discord bot on top of the sgcWebSockets trial package.
Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only.
User Manual (PDF) Comprehensive manual covering every component in the library.

Ready to Build a Discord Bot?

Download the free trial and connect to the Discord Gateway from your Delphi applications.