AutoMod¶
This section documents everything related to Discord’s AutoMod features.
Discord Models¶
AutoModRule¶
- class disnake.AutoModRule[source]¶
Represents an auto moderation rule.
New in version 2.6.
- event_type¶
The event type this rule is applied to.
- Type:
- trigger_type¶
The type of trigger that determines whether this rule’s actions should run for a specific event.
- Type:
- trigger_metadata¶
Additional metadata associated with this rule’s
trigger_type
.- Type:
- property actions[source]¶
List[Union[
AutoModBlockMessageAction
,AutoModSendAlertAction
,AutoModTimeoutAction
,AutoModAction
]]: The list of actions that will execute if a matching event triggered this rule.
- property creator[source]¶
The guild member that created this rule. May be
None
if the member cannot be found. See alsocreator_id
.- Type:
Optional[
Member
]
- property exempt_channels[source]¶
The list of channels that are exempt from this rule.
- Type:
List[
abc.GuildChannel
]
- await edit(*, name=..., event_type=..., trigger_metadata=..., actions=..., enabled=..., exempt_roles=..., exempt_channels=..., reason=None)[source]¶
This function is a coroutine.
Edits the auto moderation rule.
You must have
Permissions.manage_guild
permission to do this.All fields are optional.
Changed in version 2.9: Now raises a
TypeError
if givenactions
have an invalid type.Examples
Edit name and enable rule:
await rule.edit(name="cool new rule", enabled=True)
Add an action:
await rule.edit( actions=rule.actions + [AutoModTimeoutAction(3600)], )
Add a keyword to a keyword filter rule:
meta = rule.trigger_metadata await rule.edit( trigger_metadata=meta.with_changes( keyword_filter=meta.keyword_filter + ["stuff"], ), )
- Parameters:
name (
str
) – The rule’s new name.event_type (
AutoModEventType
) – The rule’s new event type.trigger_metadata (
AutoModTriggerMetadata
) – The rule’s new associated trigger metadata.actions (Sequence[Union[
AutoModBlockMessageAction
,AutoModSendAlertAction
,AutoModTimeoutAction
,AutoModAction
]]) – The rule’s new actions. If provided, must contain at least one action.enabled (
bool
) – Whether to enable the rule.exempt_roles (Optional[Iterable[
abc.Snowflake
]]) – The rule’s new exempt roles, up to 20. If[]
orNone
is passed then all role exemptions are removed.exempt_channels (Optional[Iterable[
abc.Snowflake
]]) – The rule’s new exempt channels, up to 50. Can also include categories, in which case all channels inside that category will be exempt. If[]
orNone
is passed then all channel exemptions are removed.reason (Optional[
str
]) – The reason for editing the rule. Shows up on the audit log.
- Raises:
ValueError – When editing the list of actions, at least one action must be provided.
TypeError – The specified
actions
are of an invalid type.Forbidden – You do not have proper permissions to edit the rule.
NotFound – The rule does not exist.
HTTPException – Editing the rule failed.
- Returns:
The newly updated auto moderation rule.
- Return type:
- await delete(*, reason=None)[source]¶
This function is a coroutine.
Deletes the auto moderation rule.
You must have
Permissions.manage_guild
permission to do this.- Parameters:
reason (Optional[
str
]) – The reason for deleting this rule. Shows up on the audit log.- Raises:
Forbidden – You do not have proper permissions to delete the rule.
NotFound – The rule does not exist.
HTTPException – Deleting the rule failed.
AutoModActionExecution¶
- class disnake.AutoModActionExecution[source]¶
Represents the data for an
on_automod_action_execution()
event.New in version 2.6.
- action¶
The action that was executed.
- rule_trigger_type¶
The trigger type of the rule that matched.
- Type:
- channel_id¶
The channel or thread ID in which the event occurred, if any. See also
channel
.- Type:
Optional[
int
]
- message_id¶
The ID of the message that matched.
None
if the message was blocked, or if the content was not part of a message. See alsomessage
.- Type:
Optional[
int
]
- alert_message_id¶
The ID of the alert message sent as a result of this action, if any. See also
alert_message
.- Type:
Optional[
int
]
- content¶
The content that matched.
Requires
Intents.message_content
to be enabled, otherwise this field will be empty.- Type:
- matched_content¶
The substring of
content
that matched the rule/keyword.Requires
Intents.message_content
to be enabled, otherwise this field will be empty.- Type:
Optional[
str
]
- property user[source]¶
The guild member that triggered this action. May be
None
if the member cannot be found. See alsouser_id
.- Type:
Optional[
Member
]
- property channel[source]¶
Optional[Union[
abc.GuildChannel
,Thread
]]: The channel or thread in which the event occurred, if any.
- property message[source]¶
The message that matched, if any. Not available if the message was blocked, if the content was not part of a message, or if the message was not found in the message cache.
- Type:
Optional[
Message
]
- property alert_message[source]¶
The alert message sent as a result of this action, if any. Only available if
action.type
issend_alert_message
and the message was found in the message cache.- Type:
Optional[
Message
]
Data Classes¶
AutoModKeywordPresets¶
- class disnake.AutoModKeywordPresets(**kwargs)[source]¶
Wraps up the pre-defined auto moderation keyword lists, provided by Discord.
- x == y
Checks if two AutoModKeywordPresets instances are equal.
- x != y
Checks if two AutoModKeywordPresets instances are not equal.
- x <= y
Checks if an AutoModKeywordPresets instance is a subset of another AutoModKeywordPresets instance.
- x >= y
Checks if an AutoModKeywordPresets instance is a superset of another AutoModKeywordPresets instance.
- x < y
Checks if an AutoModKeywordPresets instance is a strict subset of another AutoModKeywordPresets instance.
- x > y
Checks if an AutoModKeywordPresets instance is a strict superset of another AutoModKeywordPresets instance.
- x | y, x |= y
Returns a new AutoModKeywordPresets instance with all enabled flags from both x and y. (Using
|=
will update in place).
- x & y, x &= y
Returns a new AutoModKeywordPresets instance with only flags enabled on both x and y. (Using
&=
will update in place).
- x ^ y, x ^= y
Returns a new AutoModKeywordPresets instance with only flags enabled on one of x or y, but not both. (Using
^=
will update in place).
- ~x
Returns a new AutoModKeywordPresets instance with all flags from x inverted.
- hash(x)
Return the flag’s hash.
- iter(x)
Returns an iterator of
(name, value)
pairs. This allows it to be, for example, constructed as a dict or a list of pairs. Note that aliases are not shown.
Additionally supported are a few operations on class attributes.
- AutoModKeywordPresets.y | AutoModKeywordPresets.z, AutoModKeywordPresets(y=True) | AutoModKeywordPresets.z
Returns a AutoModKeywordPresets instance with all provided flags enabled.
- ~AutoModKeywordPresets.y
Returns a AutoModKeywordPresets instance with all flags except
y
inverted from their default value.
New in version 2.6.
- values[source]¶
The raw values. You should query flags via the properties rather than using these raw values.
- Type:
- classmethod all()[source]¶
A factory method that creates a
AutoModKeywordPresets
with everything enabled.
- classmethod none()[source]¶
A factory method that creates a
AutoModKeywordPresets
with everything disabled.
- profanity¶
Returns
True
if the profanity preset is enabled (contains words that may be considered swearing or cursing).- Type:
- sexual_content¶
Returns
True
if the sexual content preset is enabled (contains sexually explicit words).- Type:
AutoModTriggerMetadata¶
- defwith_changes
- class disnake.AutoModTriggerMetadata(*, keyword_filter=None, regex_patterns=None, presets=None, allow_list=None, mention_total_limit=None, mention_raid_protection_enabled=None)[source]¶
Metadata for an auto moderation trigger.
Based on the trigger type, different fields can be used with various limits:
Trigger Type
keyword_filter
regex_patterns
presets
allow_list
mention_total_limit
mention_raid_protection_enabled
✅ (x1000)
✅ (x10)
❌
✅ (x100)
❌
❌
❌
❌
❌
❌
❌
❌
❌
❌
✅
✅ (x1000)
❌
❌
❌
❌
❌
❌
✅
✅
New in version 2.6.
- keyword_filter¶
The list of keywords to check for, up to 1000 keywords. Used with
AutoModTriggerType.keyword
.See api docs for details about how keyword matching works. Each keyword must be 60 characters or less.
- Type:
Optional[Sequence[
str
]]
- regex_patterns¶
The list of regular expressions to check for. Used with
AutoModTriggerType.keyword
.A maximum of 10 regexes can be added, each with up to 260 characters.
Note
Only Rust flavored regex is currently supported, which can be tested in online editors such as Rustexp.
New in version 2.7.
- Type:
Optional[Sequence[
str
]]
- presets¶
The keyword presets. Used with
AutoModTriggerType.keyword_preset
.- Type:
Optional[
AutoModKeywordPresets
]
- allow_list¶
The keywords that should be exempt from a preset. Used with
AutoModTriggerType.keyword
(up to 100 exemptions) andAutoModTriggerType.keyword_preset
(up to 1000 exemptions).Each keyword must be 60 characters or less.
- Type:
Optional[Sequence[
str
]]
- mention_total_limit¶
The maximum number of mentions (members + roles) allowed, between 1 and 50. Used with
AutoModTriggerType.mention_spam
.- Type:
Optional[
int
]
- mention_raid_protection_enabled¶
Whether to automatically detect mention raids. Used with
AutoModTriggerType.mention_spam
.Defaults to
False
.New in version 2.9.
- Type:
Optional[
bool
]
AutoModAction¶
- class disnake.AutoModAction[source]¶
A base class for auto moderation actions.
This class is not meant to be instantiated by the user. The user-constructible subclasses are:
Actions received from the API may be of this type (and not one of the subtypes above) if the action type is not implemented yet.
New in version 2.6.
- type¶
The action type.
- Type:
AutoModBlockMessageAction¶
- class disnake.AutoModBlockMessageAction(custom_message=None)[source]¶
Represents an auto moderation action that blocks content from being sent.
New in version 2.6.
- Parameters:
custom_message (Optional[
str
]) –The custom message to show to the user when the rule is triggered. Maximum length is 150 characters.
New in version 2.9.
- type¶
The action type. Always set to
block_message
.- Type:
AutoModSendAlertAction¶
- class disnake.AutoModSendAlertAction(channel)[source]¶
Represents an auto moderation action that sends an alert to a channel.
New in version 2.6.
- Parameters:
channel (
abc.Snowflake
) – The channel to send an alert in when the rule is triggered.
- type¶
The action type. Always set to
send_alert_message
.- Type:
AutoModTimeoutAction¶
- class disnake.AutoModTimeoutAction(duration)[source]¶
Represents an auto moderation action that times out the user.
New in version 2.6.
- Parameters:
duration (Union[
int
,datetime.timedelta
]) – The duration (seconds or timedelta) for which to timeout the user when the rule is triggered.
Enumerations¶
AutoModActionType¶
- class disnake.AutoModActionType[source]¶
Represents the type of action an auto moderation rule will take upon execution.
New in version 2.6.
- block_message¶
The rule will prevent matching messages from being posted.
- send_alert_message¶
The rule will send an alert to a specified channel.
- timeout¶
The rule will timeout the user that sent the message.
Note
This action type is only available for rules with trigger type
keyword
ormention_spam
, andmoderate_members
permissions are required to use it.
AutoModEventType¶
AutoModTriggerType¶
- class disnake.AutoModTriggerType[source]¶
Represents the type of content that can trigger an auto moderation rule.
New in version 2.6.
Changed in version 2.9: Removed obsolete
harmful_link
type.- keyword¶
The rule will filter messages based on a custom keyword list.
This trigger type requires additional
metadata
.
- spam¶
The rule will filter messages suspected of being spam.