> ## Documentation Index
> Fetch the complete documentation index at: https://discord-platform-username.mintlify.site/llms.txt
> Use this file to discover all available pages before exploring further.

# Auto Moderation

> Reference for Discord's Auto Moderation system and endpoints.

export const Route = ({method, children}) => {
  return <div className="MDXRoute">
      <span className={"verb" + " " + method.toLowerCase()}>{method}</span>
      <span className="url">{children}</span>
    </div>;
};

export const ManualAnchor = ({id}) => {
  return <div className="MDXManualAnchor" id={id}></div>;
};

Auto Moderation is a feature which allows each [guild](/developers/resources/guild) to set up rules that trigger based on some criteria. For example, a rule can trigger whenever a message contains a specific keyword.

Rules can be configured to automatically execute actions whenever they trigger. For example, if a user tries to send a message which contains a certain keyword, a rule can trigger and block the message before it is sent.

### Auto Moderation Rule Object

<ManualAnchor id="auto-moderation-rule-object-auto-moderation-rule-structure" />

###### Auto Moderation Rule Structure

| Field             | Type                                                                                           | Description                                                                                                     |
| ----------------- | ---------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------------- |
| id                | snowflake                                                                                      | the id of this rule                                                                                             |
| guild\_id         | snowflake                                                                                      | the id of the guild which this rule belongs to                                                                  |
| name              | string                                                                                         | the rule name                                                                                                   |
| creator\_id       | snowflake                                                                                      | the user which first created this rule                                                                          |
| event\_type       | integer                                                                                        | the rule [event type](/developers/resources/auto-moderation#auto-moderation-rule-object-event-types)            |
| trigger\_type     | integer                                                                                        | the rule [trigger type](/developers/resources/auto-moderation#auto-moderation-rule-object-trigger-types)        |
| trigger\_metadata | object                                                                                         | the rule [trigger metadata](/developers/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata) |
| actions           | array of [action](/developers/resources/auto-moderation#auto-moderation-action-object) objects | the actions which will execute when the rule is triggered                                                       |
| enabled           | boolean                                                                                        | whether the rule is enabled                                                                                     |
| exempt\_roles     | array of snowflakes                                                                            | the role ids that should not be affected by the rule (Maximum of 20)                                            |
| exempt\_channels  | array of snowflakes                                                                            | the channel ids that should not be affected by the rule (Maximum of 50)                                         |

<ManualAnchor id="auto-moderation-rule-object-example-auto-moderation-rule" />

###### Example Auto Moderation Rule

```json theme={null}
{
  "id": "969707018069872670",
  "guild_id": "613425648685547541",
  "name": "Keyword Filter 1",
  "creator_id": "423457898095789043",
  "trigger_type": 1,
  "event_type": 1,
  "actions": [
    {
      "type": 1,
      "metadata": { "custom_message": "Please keep financial discussions limited to the #finance channel" }
    },
    {
      "type": 2,
      "metadata": { "channel_id": "123456789123456789" }
    },
    {
      "type": 3,
      "metadata": { "duration_seconds": 60 }
    }
  ],
  "trigger_metadata": {
    "keyword_filter": ["cat*", "*dog", "*ana*", "i like c++"],
    "regex_patterns": ["(b|c)at", "^(?:[0-9]{1,3}\\.){3}[0-9]{1,3}$"]
  },
  "enabled": true,
  "exempt_roles": ["323456789123456789", "423456789123456789"],
  "exempt_channels": ["523456789123456789"]
}
```

<ManualAnchor id="auto-moderation-rule-object-trigger-types" />

###### Trigger Types

Characterizes the type of content which can trigger the rule.

| Trigger Type    | Value | Description                                                                 | Max per Guild |
| --------------- | ----- | --------------------------------------------------------------------------- | ------------- |
| KEYWORD         | 1     | check if content contains words from a user defined list of keywords        | 6             |
| SPAM            | 3     | check if content represents generic spam                                    | 1             |
| KEYWORD\_PRESET | 4     | check if content contains words from internal pre-defined wordsets          | 1             |
| MENTION\_SPAM   | 5     | check if content contains more unique mentions than allowed                 | 1             |
| MEMBER\_PROFILE | 6     | check if member profile contains words from a user defined list of keywords | 1             |

<ManualAnchor id="auto-moderation-rule-object-trigger-metadata" />

###### Trigger Metadata

Additional data used to determine whether a rule should be triggered. Different fields are relevant based on the
value of [trigger\_type](/developers/resources/auto-moderation#auto-moderation-rule-object-trigger-types).

| Field                              | Type                                                                                                                    | Associated Trigger Types                  | Description                                                                       |
| ---------------------------------- | ----------------------------------------------------------------------------------------------------------------------- | ----------------------------------------- | --------------------------------------------------------------------------------- |
| keyword\_filter                    | array of strings \*                                                                                                     | KEYWORD, MEMBER\_PROFILE                  | substrings which will be searched for in content (Maximum of 1000)                |
| regex\_patterns                    | array of strings \*\*                                                                                                   | KEYWORD, MEMBER\_PROFILE                  | regular expression patterns which will be matched against content (Maximum of 10) |
| presets                            | array of [keyword preset types](/developers/resources/auto-moderation#auto-moderation-rule-object-keyword-preset-types) | KEYWORD\_PRESET                           | the internally pre-defined wordsets which will be searched for in content         |
| allow\_list                        | array of strings \*\*\*                                                                                                 | KEYWORD, KEYWORD\_PRESET, MEMBER\_PROFILE | substrings which should not trigger the rule (Maximum of 100 or 1000)             |
| mention\_total\_limit              | integer                                                                                                                 | MENTION\_SPAM                             | total number of unique role and user mentions allowed per message (Maximum of 50) |
| mention\_raid\_protection\_enabled | boolean                                                                                                                 | MENTION\_SPAM                             | whether to automatically detect mention raids                                     |

\* A keyword can be a phrase which contains multiple words. [Wildcard symbols](/developers/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies) can be used to customize how each keyword will be matched. Each keyword must be 60 characters or less.

\*\* Only Rust flavored regex is currently supported, which can be tested in online editors such as [Rustexp](https://rustexp.lpil.uk/). Each regex pattern must be 260 characters or less.

\*\*\* Each `allow_list` keyword can be a phrase which contains multiple words. [Wildcard symbols](/developers/resources/auto-moderation#auto-moderation-rule-object-keyword-matching-strategies) can be used to customize how each keyword will be matched. Rules with `KEYWORD` [trigger\_type](/developers/resources/auto-moderation#auto-moderation-rule-object-trigger-types) accept a maximum of 100 keywords. Rules with `KEYWORD_PRESET` [trigger\_type](/developers/resources/auto-moderation#auto-moderation-rule-object-trigger-types) accept a maximum of 1000 keywords.

<ManualAnchor id="auto-moderation-rule-object-trigger-metadata-field-limits" />

###### Trigger Metadata Field Limits

| Field           | Trigger Types            | MAX ARRAY LENGTH | MAX CHARACTERS PER STRING |
| --------------- | ------------------------ | ---------------- | ------------------------- |
| keyword\_filter | KEYWORD, MEMBER\_PROFILE | 1000             | 60                        |
| regex\_patterns | KEYWORD, MEMBER\_PROFILE | 10               | 260                       |
| allow\_list     | KEYWORD, MEMBER\_PROFILE | 100              | 60                        |
| allow\_list     | KEYWORD\_PRESET          | 1000             | 60                        |

<ManualAnchor id="auto-moderation-rule-object-keyword-preset-types" />

###### Keyword Preset Types

| Preset Type     | Value | Description                                                  |
| --------------- | ----- | ------------------------------------------------------------ |
| PROFANITY       | 1     | words that may be considered forms of swearing or cursing    |
| SEXUAL\_CONTENT | 2     | words that refer to sexually explicit behavior or activity   |
| SLURS           | 3     | personal insults or words that may be considered hate speech |

<ManualAnchor id="auto-moderation-rule-object-event-types" />

###### Event Types

Indicates in what event context a rule should be checked.

| Event Type     | Value | Description                                         |
| -------------- | ----- | --------------------------------------------------- |
| MESSAGE\_SEND  | 1     | when a member sends or edits a message in the guild |
| MEMBER\_UPDATE | 2     | when a member edits their profile                   |

<ManualAnchor id="auto-moderation-rule-object-keyword-matching-strategies" />

###### Keyword Matching Strategies

Use the wildcard symbol (`*`) at the beginning or end of a keyword to define how it should be matched. All keywords are case insensitive.

**Prefix** - word must start with the keyword

| Keyword   | Matches                               |
| --------- | ------------------------------------- |
| cat\*     | **cat**ch, **Cat**apult, **CAt**tLE   |
| tra\*     | **tra**in, **tra**de, **TRA**ditional |
| the mat\* | **the mat**rix                        |

**Suffix** - word must end with the keyword

| Keyword   | Matches                             |
| --------- | ----------------------------------- |
| \*cat     | wild**cat**, copy**Cat**            |
| \*tra     | ex**tra**, ul**tra**, orches**TRA** |
| \*the mat | brea**the mat**                     |

**Anywhere** - keyword can appear anywhere in the content

| Keyword     | Matches                     |
| ----------- | --------------------------- |
| \*cat\*     | lo**cat**ion, edu**Cat**ion |
| \*tra\*     | abs**tra**cted, ou**tra**ge |
| \*the mat\* | brea**the mat**ter          |

**Whole Word** - keyword is a full word or phrase and must be surrounded by whitespace

| Keyword | Matches     |
| ------- | ----------- |
| cat     | **cat**     |
| train   | **train**   |
| the mat | **the mat** |

### Auto Moderation Action Object

An action which will execute whenever a rule is triggered.

<ManualAnchor id="auto-moderation-action-object-auto-moderation-action-structure" />

###### Auto Moderation Action Structure

| Field        | Type                                                                                                   | Description                                                               |
| ------------ | ------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------- |
| type         | [action type](/developers/resources/auto-moderation#auto-moderation-action-object-action-types)        | the type of action                                                        |
| metadata? \* | [action metadata](/developers/resources/auto-moderation#auto-moderation-action-object-action-metadata) | additional metadata needed during execution for this specific action type |

\* Can be omitted based on `type`. See the `Associated Action Types` column in [action metadata](/developers/resources/auto-moderation#auto-moderation-action-object-action-metadata) to understand which `type` values require `metadata` to be set.

<ManualAnchor id="auto-moderation-action-object-action-types" />

###### Action Types

| Action Type                | Value | Description                                                                                                                                                |
| -------------------------- | ----- | ---------------------------------------------------------------------------------------------------------------------------------------------------------- |
| BLOCK\_MESSAGE             | 1     | blocks a member's message and prevents it from being posted. A custom explanation can be specified and shown to members whenever their message is blocked. |
| SEND\_ALERT\_MESSAGE       | 2     | logs user content to a specified channel                                                                                                                   |
| TIMEOUT                    | 3     | timeout user for a specified duration \*                                                                                                                   |
| BLOCK\_MEMBER\_INTERACTION | 4     | prevents a member from using text, voice, or other interactions                                                                                            |

\* A `TIMEOUT` action can only be set up for `KEYWORD` and `MENTION_SPAM` rules. The `MODERATE_MEMBERS` permission is required to use the `TIMEOUT` action type.

<ManualAnchor id="auto-moderation-action-object-action-metadata" />

###### Action Metadata

Additional data used when an action is executed. Different fields are relevant based on the
value of [action type](/developers/resources/auto-moderation#auto-moderation-action-object-action-types).

| Field             | Type      | Associated Action Types | Description                                                                            | Constraints                          |
| ----------------- | --------- | ----------------------- | -------------------------------------------------------------------------------------- | ------------------------------------ |
| channel\_id       | snowflake | SEND\_ALERT\_MESSAGE    | channel to which user content should be logged                                         | existing channel                     |
| duration\_seconds | integer   | TIMEOUT                 | timeout duration in seconds                                                            | maximum of 2419200 seconds (4 weeks) |
| custom\_message?  | string    | BLOCK\_MESSAGE          | additional explanation that will be shown to members whenever their message is blocked | maximum of 150 characters            |

### Auto Moderation Permission Requirements

Users are required to have the `MANAGE_GUILD` permission to access all Auto Moderation resources.
Some [action types](/developers/resources/auto-moderation#auto-moderation-action-object-action-types) require additional permissions, e.g. the `TIMEOUT` action type requires an additional `MODERATE_MEMBERS` permission.

## List Auto Moderation Rules for Guild

<Route method="GET">/guilds/[\{guild.id}](/developers/resources/guild#guild-object)/auto-moderation/rules</Route>

Get a list of all rules currently configured for the guild. Returns a list of [auto moderation rule](/developers/resources/auto-moderation#auto-moderation-rule-object) objects for the given guild.

<Info>
  This endpoint requires the `MANAGE_GUILD` [permission](/developers/resources/auto-moderation#auto-moderation-permission-requirements).
</Info>

## Get Auto Moderation Rule

<Route method="GET">/guilds/[\{guild.id}](/developers/resources/guild#guild-object)/auto-moderation/rules/[\{auto\_moderation\_rule.id}](/developers/resources/auto-moderation#auto-moderation-rule-object)</Route>

Get a single rule. Returns an [auto moderation rule](/developers/resources/auto-moderation#auto-moderation-rule-object) object.

<Info>
  This endpoint requires the `MANAGE_GUILD` [permission](/developers/resources/auto-moderation#auto-moderation-permission-requirements).
</Info>

## Create Auto Moderation Rule

<Route method="POST">/guilds/[\{guild.id}](/developers/resources/guild#guild-object)/auto-moderation/rules</Route>

Create a new rule. Returns an [auto moderation rule](/developers/resources/auto-moderation#auto-moderation-rule-object) on success. Fires an [Auto Moderation Rule Create](/developers/events/gateway-events#auto-moderation-rule-create) Gateway event.

<Info>
  This endpoint requires the `MANAGE_GUILD` [permission](/developers/resources/auto-moderation#auto-moderation-permission-requirements).
</Info>

<Info>
  This endpoint supports the `X-Audit-Log-Reason` header.
</Info>

<ManualAnchor id="create-auto-moderation-rule-json-params" />

###### JSON Params

| Field                 | Type                                                                                           | Description                                                                                                |
| --------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| name                  | string                                                                                         | the rule name                                                                                              |
| event\_type           | integer                                                                                        | the [event type](/developers/resources/auto-moderation#auto-moderation-rule-object-event-types)            |
| trigger\_type         | integer                                                                                        | the [trigger type](/developers/resources/auto-moderation#auto-moderation-rule-object-trigger-types)        |
| trigger\_metadata? \* | object                                                                                         | the [trigger metadata](/developers/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata) |
| actions               | array of [action](/developers/resources/auto-moderation#auto-moderation-action-object) objects | the actions which will execute when the rule is triggered                                                  |
| enabled?              | boolean                                                                                        | whether the rule is enabled (False by default)                                                             |
| exempt\_roles?        | array of snowflakes                                                                            | the role ids that should not be affected by the rule (Maximum of 20)                                       |

\* Can be omitted based on `trigger_type`. See the `Associated Trigger Types` column in [trigger metadata](/developers/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata) to understand which `trigger_type` values require `trigger_metadata` to be set.

<Info>
  See [Trigger Types](/developers/resources/auto-moderation#auto-moderation-rule-object-trigger-types) for limits on how many rules of each trigger type can be created per guild.
</Info>

## Modify Auto Moderation Rule

<Route method="PATCH">/guilds/[\{guild.id}](/developers/resources/guild#guild-object)/auto-moderation/rules/[\{auto\_moderation\_rule.id}](/developers/resources/auto-moderation#auto-moderation-rule-object)</Route>

Modify an existing rule. Returns an [auto moderation rule](/developers/resources/auto-moderation#auto-moderation-rule-object) on success. Fires an [Auto Moderation Rule Update](/developers/events/gateway-events#auto-moderation-rule-update) Gateway event.

<Info>
  Requires `MANAGE_GUILD` [permissions](/developers/resources/auto-moderation#auto-moderation-permission-requirements).
</Info>

<Info>
  All parameters for this endpoint are optional.
</Info>

<Info>
  This endpoint supports the `X-Audit-Log-Reason` header.
</Info>

<ManualAnchor id="modify-auto-moderation-rule-json-params" />

###### JSON Params

| Field                 | Type                                                                                           | Description                                                                                                |
| --------------------- | ---------------------------------------------------------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
| name                  | string                                                                                         | the rule name                                                                                              |
| event\_type           | integer                                                                                        | the [event type](/developers/resources/auto-moderation#auto-moderation-rule-object-event-types)            |
| trigger\_metadata? \* | object                                                                                         | the [trigger metadata](/developers/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata) |
| actions               | array of [action](/developers/resources/auto-moderation#auto-moderation-action-object) objects | the actions which will execute when the rule is triggered                                                  |
| enabled               | boolean                                                                                        | whether the rule is enabled                                                                                |
| exempt\_roles         | array of snowflakes                                                                            | the role ids that should not be affected by the rule (Maximum of 20)                                       |
| exempt\_channels      | array of snowflakes                                                                            | the channel ids that should not be affected by the rule (Maximum of 50)                                    |

\* Can be omitted based on `trigger_type`. See the `Associated Trigger Types` column in [trigger metadata](/developers/resources/auto-moderation#auto-moderation-rule-object-trigger-metadata) to understand which `trigger_type` values require `trigger_metadata` to be set.

## Delete Auto Moderation Rule

<Route method="DELETE">/guilds/[\{guild.id}](/developers/resources/guild#guild-object)/auto-moderation/rules/[\{auto\_moderation\_rule.id}](/developers/resources/auto-moderation#auto-moderation-rule-object)</Route>

Delete a rule. Returns a `204` on success. Fires an [Auto Moderation Rule Delete](/developers/events/gateway-events#auto-moderation-rule-delete) Gateway event.

<Info>
  This endpoint requires the `MANAGE_GUILD` [permission](/developers/resources/auto-moderation#auto-moderation-permission-requirements).
</Info>

<Info>
  This endpoint supports the `X-Audit-Log-Reason` header.
</Info>
