-
Notifications
You must be signed in to change notification settings - Fork 8
Discord GatewayIntents explained
Gateway Intents are probably one of the most misunderstood concepts of Discord bots. Though they are pretty fundamental to understand. Maybe not to it's full details but definitely to a point where you know when to use them and when not to.
Discord calculates intents based on a number. This number is achieved through bitshifting. I'm not going to go really in depth on how bitshifting works as that's not really that relevant. But just remember that a permission number should be looked at in binary to figure out what intents are enabled. It works with bits.
Intents decide which events your Discord client will receive. They were created by Discord to limit the amount of events it should send to clients. Sending all events would cause a lot of data to be sent to a client that it might not need in the first place. With intents, developers can decide what they need and request the necessary intents accordingly.
You can find a list of the intent names and what events they receive here. Below is a quick example on how you should read that.
If we look at the above image, the first intent is called Guilds. When you request that intent, you are telling the Discord api that you want to receive all events that are associated with that intent. In this case, that would mean you are getting all the events related to guilds (discord servers).
With discord.js, to get the correct name of the intent in the library, you should replace the _ with nothing and make the next letter a capital one. This means that GUILD_MODERATION would become GuildModeration, GUILD_MESSAGES would become GuildMessages, etc.
In any case, only enable intents you strictly need. Don't request intents you don't require in the first place but put some thought in what you need.
Some intents are privileged. This means you explicitly have to enable them in your developer portal before you can request them. If you require access to a privileged intent and your Discord bot ends up needing to get verified. You need explicit approval from Discord to actually use those intents. You cannot just enable them and receive the events associated to the intent when you don't need it for your Discord bot to function.
Generally the rule of thumb regarding privileged intents is that if there's no other option to do something you want, you can use the intent. This is especially true for the MessageContent intent as Discord restricted it's access behind a pretty big verification process.