AutoMod¶
This section documents everything related to Discord’s AutoMod features.
Discord Models¶
AutoModRule¶
- class disnake.AutoModRule[source]¶
This class is a Discord Model.
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
Noneif 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_guildpermission to do this.All fields are optional.
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[]orNoneis 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[]orNoneis 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.
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_guildpermission 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.
Data Classes¶
AutoModActionExecution¶
- class disnake.AutoModActionExecution[source]¶
This class is a Data Class.
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.
Noneif 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_contentto be enabled, otherwise this field will be empty.- Type:
- matched_content¶
The substring of
contentthat matched the rule/keyword.Requires
Intents.message_contentto be enabled, otherwise this field will be empty.- Type:
Optional[
str]
- property user[source]¶
The guild member that triggered this action. May be
Noneif 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.typeissend_alert_messageand the message was found in the message cache.- Type:
Optional[
Message]
AutoModKeywordPresets¶
- class disnake.AutoModKeywordPresets(**kwargs)[source]¶
This class is a Data Class.
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
yinverted 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
AutoModKeywordPresetswith everything enabled.
- classmethod none()[source]¶
A factory method that creates a
AutoModKeywordPresetswith everything disabled.
- profanity¶
Returns
Trueif the profanity preset is enabled (contains words that may be considered swearing or cursing).- Type:
- sexual_content¶
Returns
Trueif the sexual content preset is enabled (contains sexually explicit words).- Type:
AutoModTriggerMetadata¶
- defwith_changes
- class disnake.AutoModTriggerMetadata(*, keyword_filter=None, presets=None, allow_list=None, mention_total_limit=None)[source]¶
This class is a Data Class.
Metadata for an auto moderation trigger.
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.
- 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, up to 1000 keywords. Used with
AutoModTriggerType.keyword_preset.- 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]
AutoModAction¶
- class disnake.AutoModAction[source]¶
This class is a Data Class.
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[source]¶
This class is a Data Class.
Represents an auto moderation action that blocks content from being sent.
New in version 2.6.
- type¶
The action type. Always set to
block_message.- Type:
AutoModSendAlertAction¶
- class disnake.AutoModSendAlertAction(channel)[source]¶
This class is a Data Class.
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]¶
This class is a Data Class.
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]¶
This class is an Enumeration.
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
keywordormention_spam, andmoderate_memberspermissions are required to use it.
AutoModEventType¶
- class disnake.AutoModEventType[source]¶
This class is an Enumeration.
Represents the type of event/context an auto moderation rule will be checked in.
New in version 2.6.
- message_send¶
The rule will apply when a member sends or edits a message in the guild.
AutoModTriggerType¶
- class disnake.AutoModTriggerType[source]¶
This class is an Enumeration.
Represents the type of content that can trigger an auto moderation rule.
New in version 2.6.
- keyword¶
The rule will filter messages based on a custom keyword list.
This trigger type requires additional
metadata.
- harmful_link¶
The rule will filter messages containing malicious links.
- spam¶
The rule will filter messages suspected of being spam.
Events¶
See all related events!