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.
Connect to the Discord Gateway over WebSocket to build bots that react to messages, presence, guild and voice-state events in real time.
Typed Delphi/C++Builder client for the Discord Gateway WebSocket API — handles the heartbeat, identify, intents, sharding and event dispatch.
TsgcWSAPI_Discord
Windows, macOS, Linux, iOS, Android
Standard / Professional / Enterprise
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;
Implements the Discord Gateway protocol on top of TsgcWebSocketClient: IDENTIFY, RESUME, HEARTBEAT, dispatch routing.
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.
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.
Discord.Intents selects which event categories the gateway delivers (GUILD_MESSAGES, GUILD_MEMBERS, MESSAGE_CONTENT, VOICE_STATES — full intent bitmask).
Each gateway dispatch event surfaces as a typed property: OnDiscordReady, OnDiscordMessageCreate, OnDiscordGuildCreate, OnDiscordPresenceUpdate and many more.
Receive VOICE_STATE_UPDATE and VOICE_SERVER_UPDATE events — combine with the voice-WebSocket endpoint for voice channel automation.
Set Discord.Shard and Discord.ShardCount to participate in Discord's sharded gateway when your bot crosses the recommended guild threshold.
Authoritative sources for the APIs this component implements.
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. | Open | |
| Free Trial — sgcWebSockets Build your Discord bot on top of the sgcWebSockets trial package. | Open | |
| Technical Document (PDF) Features, quick start, code samples for Delphi & C++ Builder and primary-source references — this component only. | Open | |
| User Manual (PDF) Comprehensive manual covering every component in the library. | Open |