Skip to content

Commit 16e0558

Browse files
Add caveat for allowed_mentions in interactions (#7629)
* add caveat for allowed mentions in interactions * deeper rewrite of allowed mentions docs 🤠 * red ping -> notification * Update message.mdx * fix spaces * Update docs/resources/message.mdx Co-authored-by: Mark Mandel <[email protected]> * Update docs/resources/message.mdx Co-authored-by: Mark Mandel <[email protected]> --------- Co-authored-by: Mark Mandel <[email protected]>
1 parent 99140d7 commit 16e0558

File tree

1 file changed

+53
-33
lines changed

1 file changed

+53
-33
lines changed

docs/resources/message.mdx

Lines changed: 53 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,13 @@ For the `attachments` array in Message Create/Edit requests, only the `id` is re
627627

628628
### Allowed Mentions Object
629629

630-
The allowed mention field allows for more granular control over mentions without various hacks to the message. This will always validate against the message and components to avoid phantom pings (e.g. to ping everyone, you must still have `@everyone` in the message), and check against user/bot permissions.
630+
Setting the `allowed_mentions` field lets you determine whether users will receive notifications when you include mentions in the message content, or the content of components attached to that message. This field is always validated against your permissions and the presence of said mentions in the message, to avoid "phantom" pings where users receive a notification without a visible mention in the message. For example, if you want to ping everyone, including it in the `allowed_mentions` field is not enough, the mention format (`@everyone`) must also be present in the content of the message or its components. It is important to note that setting this field **does not** guarantee a push notification will be sent, as additional factors can influence this:
631+
632+
- To mention roles and notify their members, the role's `mentionable` field must be set to `true`, or the bot must have the `MENTION_EVERYONE` permission
633+
- To mention `@everyone` and `@here`, the bot must have the `MENTION_EVERYONE` permission
634+
- Setting the `SUPPRESS_NOTIFICATIONS` flag when sending a message will disable push notifications and only cause a notification badge
635+
- Users can customize their notification settings through the Discord app, which might cause them to only receive a notification badge and no push notification
636+
631637

632638
###### Allowed Mention Types
633639

@@ -637,91 +643,105 @@ The allowed mention field allows for more granular control over mentions without
637643
| User Mentions | "users" | Controls user mentions |
638644
| Everyone Mentions | "everyone" | Controls @everyone and @here mentions |
639645

640-
###### Allowed Mentions Structure
646+
###### Default Settings for Allowed Mentions
647+
648+
The default value for the `allowed_mentions` field, used when it is not passed in the body, varies depending on the context:
649+
650+
In **regular messages**, all mention types are parsed, which is equivalent to sending the following data:
651+
652+
```json
653+
{
654+
"parse": ["users", "roles", "everyone"]
655+
}
656+
```
657+
658+
In **interactions** and **webhooks**, only user mentions are parsed, which corresponds to the following:
659+
660+
```json
661+
{
662+
"parse": ["users"]
663+
}
664+
```
665+
641666

642-
| Field | Type | Description |
643-
|---------------|--------------------------------|---------------------------------------------------------------------------------------------------------------------------------------|
644-
| parse? | array of allowed mention types | An array of [allowed mention types](/docs/resources/message#allowed-mentions-object-allowed-mention-types) to parse from the content. |
645-
| roles? | list of snowflakes | Array of role_ids to mention (Max size of 100) |
646-
| users? | list of snowflakes | Array of user_ids to mention (Max size of 100) |
647-
| replied_user? | boolean | For replies, whether to mention the author of the message being replied to (default false) |
648667

649-
###### Allowed Mentions Reference
668+
| Field | Type | Description |
669+
|---------------|--------------------------------|--------------------------------------------------------------------------------------------------------------------------------------|
670+
| parse? | array of allowed mention types | An array of [allowed mention types](/docs/resources/message#allowed-mentions-object-allowed-mention-types) to parse from the content |
671+
| roles? | array of snowflakes | Array of role ids to mention, max 100 |
672+
| users? | array of snowflakes | Array of user ids to mention, max 100 |
673+
| replied_user? | boolean | For replies, whether to mention the author of the message being replied to, defaults to false |
650674

651-
Due to the complexity of possibilities, we have included a set of examples and behavior for the allowed mentions field.
675+
###### Allowed Mentions Examples
652676

653-
If `allowed_mentions` is _not_ passed in (i.e. the key does not exist), the mentions will be parsed via the message content or message component content. This corresponds with existing behavior.
677+
Because the behavior of the `allowed_mentions` field is more complex than it seems, here's a set of examples:
654678

655-
In the example below we would ping @here (and also @role124 and @user123)
679+
680+
In the following case, we are sending a regular message **without** configuring `allowed_mentions`. As a result, all included mentions will be parsed.
656681

657682
```json
658683
{
659-
"content": "@here Hi there from <@123>, cc <@&124>"
684+
"content": "@here Hello <@&1234> and <@5678> 👋"
660685
}
661686
```
662687

663-
To suppress all mentions in a message use:
688+
If you want to completely suppress all mentions in the message, you can configure the `allowed_mentions` field as we've documented above:
664689

665690
```json
666691
{
667-
"content": "@everyone hi there, <@&123>",
692+
"content": "@here Hello <@&1234> and <@5678> 👋",
668693
"allowed_mentions": {
669694
"parse": []
670695
}
671696
}
672697
```
673698

674-
This will suppress _all_ mentions in the message (no @everyone or user mention).
675699

676-
The `parse` field is mutually exclusive with the other fields. In the example below, we would ping users `123` and role `124`, but _not_ @everyone. Note that passing a `Falsy` value ([], null) into the "users" field does not trigger a validation error.
700+
It is important to note that the `parse` field is **mutually exclusive** with the other fields. In the example below, only the `1234` role and the `5678` user mentions would be parsed, but **not** the `@here` at the beginning. Passing a falsy value such as `null` or an empty array into the `users` field does not trigger a validation error.
677701

678702
```json
679703
{
680-
"content": "@everyone <@123> <@&124>",
704+
"content": "@here Hello <@&1234> and <@5678> 👋",
681705
"allowed_mentions": {
682706
"parse": ["users", "roles"],
683707
"users": []
684708
}
685709
}
686710
```
687711

688-
In the next example, we would ping @everyone, (and also users `123` and `124` if they suppressed
689-
@everyone mentions), but we would not ping any roles.
712+
713+
In this next example, **only** `@everyone` would be parsed, as well as users `1234` and `5678` in case they suppressed `@everyone` mentions in their settings.
690714

691715
```json
692716
{
693-
"content": "@everyone <@123> <@124> <@125> <@&200>",
717+
"content": "@everyone <@1234> <@5678> <@&789> 👋",
694718
"allowed_mentions": {
695719
"parse": ["everyone"],
696-
"users": ["123", "124"]
720+
"users": ["1234", "5678"]
697721
}
698722
}
699723
```
700724

701-
Due to possible ambiguities, not all configurations are valid. An _invalid_ configuration is as follows
725+
726+
Due to possible ambiguities, not all configurations are accepted. Here's an example of an *invalid* configuration, because it includes both `parse` and `users`, despite those fields being mutually exclusive, causing a validation error.
702727

703728
```json
704729
{
705-
"content": "@everyone <@123> <@124> <@125> <@&200>",
730+
"content": "@everyone <@1234> <@5678> <@9012> <@&200>",
706731
"allowed_mentions": {
707732
"parse": ["users"],
708-
"users": ["123", "124"]
733+
"users": ["1234", "5678"]
709734
}
710735
}
711736
```
712737

713-
Because `parse: ["users"]` and `users: [123, 124]` are both present, we would throw a validation error.
714-
This is because the conditions cannot be fulfilled simultaneously (they are mutually exclusive).
715-
716-
Any entities with an ID included in the list of IDs can be mentioned. Note that the IDs of entities not present in the message content or message component content will simply be ignored.
717-
e.g. The following example is valid, and would mention user 123, but _not_ user 125 since there is no mention of
718-
user 125 in the content.
738+
Any entities whose id is included can be mentioned. Do note the API will silently ignore entities whose id are present in the `allowed_mentions` field, but not in the content of the message or its components. For example, in the following configuration, the user 123 mention would be parsed because it is present in the `content`. However, since there is no mention of user 456 in the `content`, they would not be notified.
719739

720740
```json
721741
{
722-
"content": "<@123> Time for some memes.",
742+
"content": "<@123> Time for some memes 🤠",
723743
"allowed_mentions": {
724-
"users": ["123", "125"]
744+
"users": ["123", "456"]
725745
}
726746
}
727747
```

0 commit comments

Comments
 (0)