Intents are an important part of Discord which I briefly cover in this tutorial part, but which deserve their own section explaining them in more depth, so here it is!
1 - What are Gateway Intents?
Gateway intents are a way of getting only the data your application needs from the Discord gateway. When you first identify with the gateway upon starting your bot you send the intents you are going to use as an integer which represents a field of bits that describe which intents you need.
There are a few different gateway intents that you can select:
|Gateway Intent Name in Docs||Bit Shift||Description||Privileged|
||1 << 0||Allows you to receive guild events like joining/leaving guilds, role events, and channel events.||No|
||1 << 1||Allows you to receive member events like joins and leaves.||Yes|
||1 << 2||Allowd you to receive ban add and remove events.||No|
||1 << 3||Allows you to receive emoji updates.||No|
||1 << 4||Allows you to receive integration update events.||No|
||1 << 5||Allows you to receive webhook update events.||No|
||1 << 6||Allows you to receive invite create and delete events.||No|
||1 << 7||Allows you to receive voice state update events.||No|
||1 << 8||Allows you to receive members' presence updates.||Yes|
||1 << 9||Allows you to receive message events like create and delete from guilds.||No|
||1 << 10||Allows you to receive message reaction events like add and remove on guild messages.||No|
||1 << 11||Allows you to receive typing events in guilds.||No|
||1 << 12||Allows you to receive message events like create and delete from DMs.||No|
||1 << 13||Allows you to receive message reaction events like add and remove on DM messages.||No|
||1 << 14||Allows you to receive typing events in DMs.||No|
Enabling Privileged Intents
To enable privileged intents for your application, first head over to the Discord developer portal and click on your application. Next, head to the Bot tab on the left, and scroll down to the privileged intents section:
Now you can select either or both of these intents so that you can use them in your code. Bear in mind that if one of these intents is not enabled on this page you cannot use it when connecting to the gateway.
Using Intents in Your Bot
Let's start out with a simple bot setup:
from discord.ext import commands bot = commands.Bot(command_prefix="!")
This example has most of the intents enabled, all except members and presences. There are a couple of ways we can enable these intents, the first option being using all intents - which you should only use if you actually use both memebrs and presence intents:
from discord.ext import commands from discord import Intents bot = commands.Bot(command_prefix="!", intents=Intents.all())
The next method is to create a default intents object, and explicitly enable an intent on it, in this example I'll enabled the members intent since this is the most common one to need:
from discord.ext import commands from discord import Intents intents = Intents.default() intents.members = True bot = commands.Bot(command_prefix="!", intents=intents)
That's pretty much it for gateway intents, they're not too complicated but can definitely catch you out if you don't know about them, so watch out for where you might need to change them!