Skip to content

Lesson 1 of 9 · 24m

Gateway Bots Versus HTTP Interaction Apps

Understand the two Discord delivery models, what each one can observe, and why production bots often use both.

The first architectural mistake I see in Discord bots is treating Discord like a normal HTTP API with a websocket bolted on. It is closer to two products sharing one identity system: a stateful event stream for servers your bot lives in, and a request/response interaction surface for commands. If you choose the wrong one, everything downstream — scaling, permissions, moderation, even deployment — becomes harder than it needs to be.

The gateway is a stateful relationship

A gateway bot opens one or more persistent websocket connections, identifies with a token and intents, receives a heartbeat schedule, and then consumes events:

Discord Gateway  <-- heartbeats/events -->  shard process
    READY, GUILD_CREATE, MESSAGE_CREATE,
    GUILD_MEMBER_ADD, INTERACTION_CREATE, ...

The important property is not merely that events arrive quickly. The important property is that Discord expects you to maintain connection state: sequence numbers, sessions, resumes, heartbeats, and shard identity. Lose that state cleanly and you can resume. Lose it badly and you re-identify, possibly burning your identify concurrency budget.

Interactions can be request/response

Slash commands, buttons, select menus, and modals are interactions. A gateway bot receives them as INTERACTION_CREATE events, but an interaction-only app can instead expose a public HTTPS endpoint and verify Discord's Ed25519 signatures:

from nacl.signing import VerifyKey

verify_key = VerifyKey(bytes.fromhex(DISCORD_PUBLIC_KEY))
verify_key.verify(
    (timestamp + body).encode(),
    bytes.fromhex(signature),
)

That model is attractive for small tools because there is no always-on websocket. It is limiting because you do not automatically receive message content, member joins, presence, audit events, or other guild telemetry. The interaction is the request context you get; anything else must be fetched or already stored.

The hidden tradeoff is state ownership

Gateway bots naturally accumulate guild, channel, member, role, and cache state. HTTP interaction apps naturally treat every invocation as stateless. Production bots often need both: gateway events for awareness and enforcement, interaction handling for commands and components.

A common split looks like this:

event worker(s): gateway shards -> event log/queue -> moderation/cache updates
interaction worker(s): signed HTTP endpoint or gateway interaction events
shared services: permissions, guild settings, audit evidence, action execution

The split is not about fashion. It isolates the stateful reconnecting machinery from latency-sensitive user interaction code.

Ask these questions before choosing

  • Does the bot need to observe messages or member activity without being invoked?
  • Does it need server-local persistent state, or can every action be fetched on demand?
  • Will it grow past one process or 2,500 guilds, where sharding is unavoidable?
  • Can you expose and protect a public interaction endpoint?
  • What happens during deploys, reconnects, and Discord outages?

A moderation bot almost always needs the gateway. A stateless utility with slash commands can begin as an HTTP interaction app. A large community bot usually ends up with a hybrid even if it did not start that way.

Field notes

  • INTERACTION_CREATE over the gateway is not proof that your bot is stateless; it means you chose gateway delivery for interactions.
  • Webhook-style interaction endpoints still have strict acknowledgement deadlines; do not run the whole job synchronously.
  • Verifying Discord signatures is mandatory. Check timestamps and reject unsigned or malformed payloads before parsing business logic.
  • Do not create a second bot just to separate commands from moderation until you understand the operational cost of two identities.

Was this lesson helpful?

Sign in to rate