Section titled IntentsIntents

Intents are an important part of establishing a WebSocket connection, as they define behaviour regarding gateway events and impact received data via the REST API.

Section titled UsageUsage


_10
import { Client, GatewayIntentBits } from 'discord.js';
_10
_10
const client = new Client({
_10
intents: [GatewayIntentBits.Guilds],
_10
});

This is the most basic usage of intents for discord.js. By specifying GatewayIntentBits.Guilds, we will receive gateway events regarding guilds. This includes receiving information about guilds as the bot starts up, such as the roles in the guild and the respective shard id.

The full list of GatewayIntentBits one can specify can be found on the documentation. An explanation of what each intent does can be found on Discord's documentation.

Section titled ConsiderationsConsiderations

In discord.js, some intents require an extra bit of consideration.

Section titled GatewayIntentBits.GuildsGatewayIntentBits.Guilds

discord.js relies heavily on caching in the library. It is recommended to set at least the GatewayIntentBits.Guilds intent for discord.js to avoid these pitfalls.

Section titled GatewayIntentBits.GuildMembersGatewayIntentBits.GuildMembers

Fetching members in a guild via GuildMemberManager#fetch() requests them over the gateway. As such, this intent is required and you may receive a timeout error if this intent is not specified.

Section titled GatewayIntentBits.DirectMessagesGatewayIntentBits.DirectMessages

This intent is required to receive direct messages. In discord.js however, you must specify partials as well. See the partials topic on how this is done.

Section titled GatewayIntentBits.MessageContentGatewayIntentBits.MessageContent

Unlike other intents, this only populates user-generated fields. See Discord's documentation on what exactly this intent unveils.

It is a common mistake to not see the message content in a message—this is usually because this intent is not specified.

This is a privileged intent. Read on for more information.

Info

Section titled Privileged intentsPrivileged intents

Some gateway events are considered privileged. Currently, these are:

  • GatewayIntentBits.GuildPresences
  • GatewayIntentBits.GuildMembers
  • GatewayIntentBits.MessageContent

To use these intents, you will need to enable them in the developer portal. If your bot is in over 75 guilds, you will need to verify your bot and request usage of your desired intents.

Carefully think if you need these intents. They are opt-in so users across the platform can enjoy a higher level of privacy. Presences can expose some personal information, such as the games being played and overall online time. You might find that it isn't necessary for your bot to have this level of information about all guild members at all times.

Section titled Disallowed intentsDisallowed intents

Should you receive an error stating you are using disallowed intents, please review your developer dashboard settings for all privileged intents you use. Check the Discord API documentation for up-to-date information.