Gateway Intents

Discord allows you to "subscribe" to specific groups of events. These "subscriptions" are called intent. Disabling intents that are not required for your bot can significantly increase your bot's performance.

πŸ“‹ List of Intents

Below you can find a table with all intents supported by Discord.

IntentSafe to DisablePrivileged
GUILDS❌❌
GUILD_MEMBERSβœ”οΈβœ”οΈ
GUILD_BANS⚠️*❌
GUILD_EMOJIS⚠️*❌
GUILD_INTEGRATIONSβœ”οΈβŒ
GUILD_WEBHOOKSβœ”οΈβŒ
GUILD_INVITESβœ”οΈβŒ
GUILD_VOICE_STATES⚠️*❌
GUILD_PRESENCESβœ”οΈβœ”οΈ
GUILD_MESSAGESβœ”οΈβŒ
GUILD_MESSAGE_REACTIONSβœ”οΈβŒ
GUILD_MESSAGE_TYPINGβœ”οΈβŒ
DIRECT_MESSAGESβœ”οΈβŒ
DIRECT_MESSAGE_REACTIONSβœ”οΈβŒ
DIRECT_MESSAGE_TYPINGβœ”οΈβŒ
MESSAGE_CONTENTβœ”οΈβœ”οΈ
AUTO_MODERATION_CONFIGURATIONβœ”οΈβŒ
AUTO_MODERATION_EXECUTIONβœ”οΈβŒ

* Will most likely work, but needs further testing

Good to know!

Guild is a synonym for servers, commonly used in Discord's API. See Glossary.

πŸ’‘ What Happens When I Disable Some Intents?

When you disable some of the listed intents, Javacord will not fire events that belong to the intents and will not update these specific parts of the cache.

At the moment, we don't have a list which events are affected by which intents (but it will come soonℒ️). However, most intents should be self-explanatory. E.g. when you disable the DIRECT_MESSAGES intent, your bot will not receive any private messages.

πŸ‘‘ Privileged Intents

Some intents are defined as "privileged" due to the sensitive nature of the data. To use these intents, you have to go to your bot in the Developer Portalopen in new window (where you created bot) and manually enable the intents:

There are some additionally restrictions for bots that are in over 100 servers:

  • Your bot must be verified
  • Your bot must be whitelisted to use this intents

Take a look at the official article from Discord about this topic and how to verify your bot: Bot Verification and Data Whitelistingopen in new window.

❗ Notable Intents

The following two intents are especially noteworthy: GUILD_MEMBERS and GUILD_PRESENCES. Besides being privileged, they have some special implications for Javacord:

GUILD_PRESENCES

This intent is required to get updates about a user's status (i.e., if they are online, what game they are playing, ...). Additionally, without this intent it might take considerably longer to cache all users because of ratelimits (up to 10 minutes for shards with 1000 servers). It is advised against setting DiscordApiBuilder#setWaitForAllUsersOnStartup(true) without this intent, unless absolutely necessary.

GUILD_MEMBERS

This intent is required to keep all users in Javacord's cache. Without this intent, methods like Server#getMembers() or DiscordApi#getCachedUsers() will return empty collections. However, you will still be able to access users from objects like messages, e.g. Message#getUserAuthor() will still work.

MESSAGE_CONTENT

This intent is a bit different to the other as it does not act as a toggle to receive any events. It's sole purpose is to receive the message content, attachments, components, and embeds. Otherwise, these fields will be empty when you receive a Message object.

βš™οΈ Setting Intents

Javacord allows you to specify intents in the DiscordApiBuilder prior to login. There are many options to set intents. The following example code shows the most common ones:

Set All Non-Privileged Intents (Default)

This method enables all non-privileged intents. This is the default setting in Javacord.

DiscordApi api = new DiscordApiBuilder()
    .setToken("topc secret")
    .setAllNonPrivilegedIntents()
    .login()
    .join();

Set All Non-Privileged Intents Except

This method enabled all non-privileged intents, except the given ones.

DiscordApi api = new DiscordApiBuilder()
    .setToken("topc secret")
    .setAllNonPrivilegedIntentsExcept(Intent.GUILD_WEBHOOKS)
    .login()
    .join();

Set All Intents

This method enabled all intents.

DiscordApi api = new DiscordApiBuilder()
    .setToken("topc secret")
    .setAllIntents()
    .login()
    .join();

Set All Intents Except

This method enabled all intents, except the given ones.

DiscordApi api = new DiscordApiBuilder()
    .setToken("topc secret")
    .setAllIntentsExcept(Intent.GUILD_PRESENCES, Intent.GUILD_WEBHOOKS)
    .login()
    .join();

Set Intents

This method only enables the given intents.

DiscordApi api = new DiscordApiBuilder()
    .setToken("topc secret")
    .setIntents(Intent.GUILDS, Intent.DIRECT_MESSAGES)
    .login()
    .join();

Add Intents

This method adds the intents to the currently enabled ones(by default all non-privileged). This is useful i.e. if you only want to enable 1 privileged intent like the MESSAGE_CONTENT

DiscordApi api = new DiscordApiBuilder()
    .setToken("topc secret")
    .addIntents(Intent.MESSAGE_CONTENT)
    .login()
    .join();