Section titled IntentsIntents
Intents are an important part of establishing a WebSocket connection, as they define behavior regarding gateway events and impact received data via the REST API.
Section titled UsageUsage
_10import { Client, GatewayIntentBits } from 'discord.js';_10_10const client = new Client({_10 intents: [GatewayIntentBits.Guilds],_10});
This is the most basic usage of intents for discord.js. By specifying GatewayIntentBits.Guilds
, your bot will receive gateway events regarding guilds. This includes receiving initial information about guilds it is in at startup, such as role data.
You can find the full list of GatewayIntentBits
on the documentation and an explanation of what each intent does on Discord's API 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. We recommend you set at least the GatewayIntentBits.Guilds
intent 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.
This is a privileged intent. Read on for more information.
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.
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 it 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.