Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add message content intent faq #30

Merged
merged 4 commits into from
Mar 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 35 additions & 4 deletions guide/docs/popular-topics/intents.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ An intent basically allows a bot to subscribe to specific buckets of events. The

These intents are passed to the constructor of <DocsLink ext="commands" reference="disnake.ext.commands.Bot">commands.Bot</DocsLink> or its subclasses (<DocsLink reference="disnake.AutoShardedClient" />, <DocsLink ext="commands" reference="disnake.ext.commands.AutoShardedBot" />, <DocsLink ext="commands" reference="disnake.ext.commands.Bot" />) with the `intents` argument.

If intents are not passed, then the library defaults to every intent being enabled except the privileged intents, currently <DocsLink reference="disnake.Intents.members" /> and <DocsLink reference="disnake.Intents.presences" />.
If intents are not passed, then the library defaults to every intent being enabled except the privileged intents, currently <DocsLink reference="disnake.Intents.members" />, <DocsLink reference="disnake.Intents.presences" /> and <DocsLink reference="disnake.Intents.message_content" /> .

## What intents are needed?

Expand All @@ -35,7 +35,7 @@ client = disnake.Client(intents=intents)
# or,
from disnake.ext import commands

bot = commands.Bot(command_prefix="!", intents=intents)
bot = commands.Bot(command_prefix=commands.when_mentioned_or("!"), intents=intents)
```

:::note
Expand All @@ -58,7 +58,7 @@ client = disnake.Client(intents=intents)
# or
from disnake.ext import commands

bot = commands.Bot(command_prefix="!", intents=intents)
bot = commands.Bot(command_prefix=commands.when_mentioned, intents=intents)
```

## Privileged Intents
Expand Down Expand Up @@ -106,6 +106,11 @@ Even if you enable intents through the developer portal, you still have to enabl

This is a quick checklist to see if you need specific privileged intents.

### Message Content Intent

- Whether you want a prefix that isn't the bot mention.
- Whether you want to see what the content of a message was. This includes content, embeds, attachments, and components.

### Presence Intent

- Whether you use <DocsLink reference="disnake.Member.status" /> at all to track member statuses.
Expand Down Expand Up @@ -187,9 +192,35 @@ client = disnake.Client(intents=intents)
# or
from disnake.ext import commands

bot = commands.Bot(command_prefix="!", intents=intents)
bot = commands.Bot(command_prefix=commands.when_mentioned, intents=intents)
```

### Why do most messages have no content?

As of April 30th 2022, Discord has blocked message content from being sent to bots that do not declare the <DocsLink reference="disnake.Intents.message_content">message_content</DocsLink> intent when connecting to discord.

If you are on version 2.4 or before, your bot will be able to access message content without the intent enabled in the code. However, as of version 2.5, it is required to enable <DocsLink reference="disnake.Intents.message_content">message_content</DocsLink> to receive message content over the gateway.

:::note

No matter which disnake version you use, you will be required to turn on the message_content intent in the [Discord Developer Portal](https://discord.com/developers/applications).

:::

Message content refers to four attributes on the <DocsLink reference="disnake.Message" /> object:

- <DocsLink reference="disnake.Message.content">content</DocsLink>
- <DocsLink reference="disnake.Message.embeds">embeds</DocsLink>
- <DocsLink reference="disnake.Message.attachments">attachments</DocsLink>
- <DocsLink reference="disnake.Message.components">components</DocsLink>

You will always receive message content in the following cases even without the message content intent:

- Messages the bot sends
- Messages the bot receives in <DocsLink reference="disnake.DMChannel" /> instances
- Messages in which the bot is mentioned
- Messages received as part of an interaction (for example, a message command)

### Why does `on_ready` take so long to fire?

As part of the API change regarding intents, Discord also changed how members are loaded in the beginning. Originally the library could request 75 guilds at once and only request members from guilds that have the <DocsLink reference="disnake.Guild.large">Guild.large</DocsLink> attribute set to `True`. With the new intent changes, Discord mandates that we can only send 1 guild per request. This causes a 75x slowdown which is further compounded by the fact that _all_ guilds, not just large guilds are being requested.
Expand Down