Gateway Intents

Intents

Discord has been working on a way for gateway clients to only subscribe to a select few types of events to reduce unneeded work.

The Discord gateway can be spammy. Like, really spammy. For a long time, the dev community has asked us for a way to “subscribe” to only the gateway events their bots need, saving tons of computational cost. With the Gateway Intents system, you tell us on IDENTIFY what you’re planning to do—your "intents"—and we'll send you only the gateway events that you need.

Intents are an integer bit field specified on Identify payloads (intents: int), similar to permissions/flags.

With the recent announcement made, we are allowed a glimpse of how this will be implemented.

While this is certainly a welcome change, it puts Kord into a difficult position.

Intents remove our single source of truth.

So far, we have prioritized data consistency when it comes to caching, only caching entities that were generated by the gateway since we can be certain that those entities will also get their update and remove events. This has allowed us to handle the Gateway as a single source of truth, and cache anything that comes through it without fear of being out of sync (give or take a few ms) with reality.

The intent system allows users to disable some of these events, meaning that we can't assure the lifetime of all entities anymore:

  • Caching a Member from a GUILD_CREATE would be an error if the GUILD_MEMBERS intent is not enabled.
  • Caching messages would lead to inconsistencies if GUILD_MESSAGE_REACTIONS is not also enabled.
  • etc

What to cache with Intents?

This puts it in a difficult spot when it comes to caching, some of the approaches we've thought about:

Remove implicit caching from Kord.

Removing any form of implicit caching would solve this problem, but in the same way as taking down a house with a wrecking ball to solve a hole in the wall. This obviously comes with serious performance penalties.

Allow stale information in the cache.

A sure way to run into bugs and unexpected errors.

Only cache entities for which all required intents are enabled.

This has the potential to limit the usefulness of cache severely as some seemingly unrelated intents need to be enabled for caching to work. (e.g. message caching would not just need the guild messages enabled but also the guild message reactions). Additionally, this would introduce a lot more moving parts into Kord to communicate the enabling and disabling of cached entities between the core and gateway module.

Whatever route we take, it's clear that the usefulness of cache will suffer dramatically, and may result in us having to rethink caching completely.

Make use of the passive events received.

Events that are not mentioned in the announcement are considered passive (always received) so we can make use of these to get the information we need for example (Request Guild Members) event allows asking for members, thus if someone needs to interact with a member while they don't have the intent needed, they can use it to get the members in question then, we can cache them.

Edited by Hope