You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: docs/resources/message.mdx
+53-33Lines changed: 53 additions & 33 deletions
Original file line number
Diff line number
Diff line change
@@ -627,7 +627,13 @@ For the `attachments` array in Message Create/Edit requests, only the `id` is re
627
627
628
628
### Allowed Mentions Object
629
629
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
+
631
637
632
638
###### Allowed Mention Types
633
639
@@ -637,91 +643,105 @@ The allowed mention field allows for more granular control over mentions without
637
643
| User Mentions | "users" | Controls user mentions |
| 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) |
| 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 |
650
674
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
652
676
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:
654
678
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.
656
681
657
682
```json
658
683
{
659
-
"content": "@here Hi there from <@123>, cc <@&124>"
684
+
"content": "@here Hello <@&1234> and <@5678> 👋"
660
685
}
661
686
```
662
687
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:
664
689
665
690
```json
666
691
{
667
-
"content": "@everyone hi there, <@&123>",
692
+
"content": "@here Hello <@&1234> and <@5678> 👋",
668
693
"allowed_mentions": {
669
694
"parse": []
670
695
}
671
696
}
672
697
```
673
698
674
-
This will suppress _all_ mentions in the message (no @everyone or user mention).
675
699
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.
677
701
678
702
```json
679
703
{
680
-
"content": "@everyone <@123> <@&124>",
704
+
"content": "@here Hello <@&1234> and <@5678> 👋",
681
705
"allowed_mentions": {
682
706
"parse": ["users", "roles"],
683
707
"users": []
684
708
}
685
709
}
686
710
```
687
711
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.
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.
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.
0 commit comments