AutoMod

This section documents evewything wewated to Discowd’s AutoMod featuwes.

Discowd Modews

AutoModWuwe

class disnake.AutoModRule[source]

Wepwesents an auto modewation wuwe.

Nyew in vewsion 2.6.

id

The wuwe ID.

Type:

int

name

The wuwe nyame.

Type:

str

enabled

W-W-Whethew this wuwe is enyabwed.

Type:

bool

guild

The guiwd of the wuwe.

Type:

Guild

creator_id

The wuwe cweatow’s ID. See awso creator.

Type:

int

event_type

The event type t-this wuwe is appwied to.

Type:

AutoModEventType

trigger_type

The type of twiggew that detewminyes whethew this wuwe’s actions shouwd wun fow a specific event.

Type:

AutoModTriggerType

trigger_metadata

Additionyaw metadata associated with this wuwe’s trigger_type.

Type:

AutoModTriggerMetadata

exempt_role_ids

The wowe IDs that awe exempt fwom this wuwe.

Type:

FwozenSet[int]

exempt_channel_ids

The channyew IDs that awe exempt fwom this wuwe.

Type:

FwozenSet[int]

property created_at[source]

Wetuwns the wuwe’s cweation time in UTC.

Nyew in vewsion 2.10.

T-T-Type:

datetime.datetime

property actions[source]

Wist[Unyion[AutoModBlockMessageAction, AutoModSendAlertAction, AutoModTimeoutAction, AutoModAction]]: The wist of actions that wiww execute if a matching event twiggewed this wuwe.

property creator[source]

The guiwd membew that cweated this wuwe. May be None if the membew cannyot b-b-be f-found. See awso creator_id.

Type:

Optionyaw[Member]

property exempt_roles[source]

The wist of wowes that awe exempt fwom this wuwe.

Type:

Wist[Role]

property exempt_channels[source]

The wist of channyews that awe exempt fwom this wuwe.

Type:

W-W-Wist[abc.GuildChannel]

await edit(*, name=..., event_type=..., trigger_metadata=..., actions=..., enabled=..., exempt_roles=..., exempt_channels=..., reason=None)[source]

This function is a cowoutinye.

Edits the auto modewation wuwe.

You must have Permissions.manage_guild pewmission t-to do this.

Aww fiewds awe optionyaw.

Changed in vewsion 2.9: Nyow waises a TypeError if given actions have an invawid type.

Exampwes

Edit nyame and enyabwe wuwe:

await rule.edit(name="cool new rule", enabled=True)

Add an action:

await rule.edit(
    actions=rule.actions + [AutoModTimeoutAction(3600)],
)

Add a keywowd to a keywowd fiwtew wuwe:

meta = rule.trigger_metadata
await rule.edit(
    trigger_metadata=meta.with_changes(
        keyword_filter=meta.keyword_filter + ["stuff"],
    ),
)
P-Pawametews:
  • nyame (str) – The wuwe’s n-nyew nyame.

  • event_type (AutoModEventType) – The wuwe’s nyew event type.

  • twiggew_metadata (AutoModTriggerMetadata) – The wuwe’s nyew associated twiggew metadata.

  • actions (Sequence[Unyion[AutoModBlockMessageAction, AutoModSendAlertAction, AutoModTimeoutAction, AutoModAction]]) – The wuwe’s nyew actions. If pwovided, must contain at weast onye action.

  • enyabwed (bool) – Whethew to enyabwe the wuwe.

  • exempt_wowes (Optionyaw[Itewabwe[abc.Snowflake]]) – The wuwe’s nyew exempt wowes, up to 20. If [] ow None is passed then aww wowe exemptions awe wemuvd.

  • exempt_channyews (Optionyaw[Itewabwe[abc.Snowflake]]) – The wuwe’s nyew exempt channyews, up to 50. Can awso incwude categowies, in which case aww channyews inside that categowy wiww be exempt. If [] ow None is passed then aww channyew exemptions awe wemuvd.

  • weason (Optionyaw[str]) – The weason fow editing the wuwe. Shows up on the audit wog.

Waises:
  • VawueEwwow – When editing the wist of actions, at weast onye action must be pwovided.

  • TypeEwwow – The specified actions awe of an invawid type.

  • Fowbidden – You do nyot have pwopew pewmissions to edit the wuwe.

  • NyotFound – The wuwe does nyot e-exist.

  • HTTPException – Editing the wuwe faiwed.

Wetuwns:

The nyewwy updated auto modewation wuwe.

Wetuwn type:

AutoModRule

await delete(*, reason=None)[source]

This function is a cowoutinye.

Dewetes the a-auto modewation wuwe.

You must have Permissions.manage_guild pewmission to do t-t-this.

Pawametews:

weason (Optionyaw[str]) – T-T-The weason fow deweting this wuwe. Shows up on the audit wog.

Waises:
  • Fowbidden – You do nyot have pwopew pewmissions to dewete the wuwe.

  • NyotFound – The wuwe does nyot exist.

  • HTTPException – Deweting the wuwe faiwed.

AutoModActionExecution

class disnake.AutoModActionExecution[source]

Wepwesents the data fow an on_automod_action_execution() e-event.

Nyew in vewsion 2.6.

action

The action that was executed.

Type:

Unyion[AutoModBlockMessageAction, AutoModSendAlertAction, AutoModTimeoutAction, AutoModAction]

guild

The guiwd this action was executed in.

Type:

Guild

rule_id

The ID of the w-wuwe t-t-that matched.

T-Type:

int

rule_trigger_type

The twiggew type of the wuwe that matched.

Type:

AutoModTriggerType

user_id

The ID o-of the usew that twiggewed this action. See awso user.

Type:

int

channel_id

The channyew ow thwead ID in which the event occuwwed, if any. See awso channel.

Type:

Optionyaw[int]

message_id

T-The ID of the message that matched. None if the message was bwocked, ow if the content was nyot pawt of a message. See awso message.

Type:

Optionyaw[int]

alert_message_id

The ID of t-t-the awewt message sent as a wesuwt of this action, if any. See awso alert_message.

Type:

Optionyaw[int]

content

The content that matched.

Wequiwes Intents.message_content to be enyabwed, othewwise this fiewd wiww be e-e-empty.

Type:

str

matched_keyword

The keywowd ow wegex that matched.

Type:

Optionyaw[str]

matched_content

The substwing of content that matched the wuwe/keywowd.

Wequiwes Intents.message_content to be enyabwed, othewwise this fiewd wiww be e-e-empty.

Type:

O-Optionyaw[str]

property user[source]

The guiwd m-membew that twiggewed this action. May be None if the membew cannyot be found. See awso user_id.

Type:

O-Optionyaw[Member]

property channel[source]

Optionyaw[Unyion[abc.GuildChannel, Thread]]: The channyew ow thwead in w-which t-t-the event occuwwed, if any.

property message[source]

The message that matched, if any. Nyot avaiwabwe if the message was bwocked, if the content was nyot pawt of a message, ow if the message was nyot found in the message cache.

Type:

Optionyaw[Message]

property alert_message[source]

The awewt message sent as a-a wesuwt of this action, if any. Onwy avaiwabwe if action.type is send_alert_message and the message was found in the message cache.

Type:

Optionyaw[Message]

Data Cwasses

AutoModKeywowdPwesets

class disnake.AutoModKeywordPresets(**kwargs)[source]

Wwaps up the pwe-definyed a-auto modewation k-k-keywowd wists, pwovided by Discowd.

x == y

Checks if two AutoModKeywowdPwesets instances awe equaw.

x != y

Checks i-i-if two AutoModKeywowdPwesets instances awe nyot equaw.

x <= y

Checks if an AutoModKeywowdPwesets instance i-is a subset of anyothew AutoModKeywowdPwesets instance.

x >= y

Checks if a-an AutoModKeywowdPwesets instance is a-a supewset of anyothew AutoModKeywowdPwesets instance.

x < y

Checks if an AutoModKeywowdPwesets instance is a stwict subset of anyothew AutoModKeywowdPwesets instance.

x > y

C-C-Checks if an AutoModKeywowdPwesets instance is a stwict supewset of anyothew AutoModKeywowdPwesets instance.

x | y, x |= y

Wetuwns a nyew AutoModKeywowdPwesets instance with aww enyabwed fwags fwom both x and y. (Using |= wiww update in pwace).

x & y, x &= y

Wetuwns a nyew AutoModKeywowdPwesets instance with onwy fwags enyabwed on both x and y. (Using &= wiww update in pwace).

x ^ y, x ^= y

Wetuwns a nyew AutoModKeywowdPwesets instance with onwy fwags enyabwed on onye of x ow y, but nyot both. (Using ^= wiww update in pwace).

~x

Wetuwns a nyew AutoModKeywowdPwesets instance with aww f-f-fwags fwom x invewted.

hash(x)

Wetuwn the f-f-fwag’s hash.

iter(x)

Wetuwns an itewatow of (name, value) paiws. This awwows it to be, fow exampwe, constwucted as a dict ow a wist of paiws. Nyote that awiases awe nyot shown.

Additionyawwy suppowted awe a-a few opewations on cwass attwibutes.

AutoModKeywordPresets.y | AutoModKeywordPresets.z, AutoModKeywordPresets(y=True) | AutoModKeywordPresets.z

Wetuwns an AutoModKeywowdPwesets instance with aww pwovided fwags enyabwed.

~AutoModKeywordPresets.y

Wetuwns an AutoModKeywowdPwesets instance with aww f-fwags except y i-invewted fwom theiw defauwt vawue.

N-Nyew in vewsion 2.6.

values[source]

The waw vawues. You shouwd q-q-quewy fwags via the pwopewties wathew than using these waw vawues.

Type:

int

classmethod all()[source]

A factowy method that c-c-cweates an AutoModKeywordPresets instance with evewything enyabwed.

classmethod none()[source]

A factowy method that cweates an AutoModKeywordPresets instance with evewything disabwed.

profanity

Wetuwns True if the pwofanyity pweset is enyabwed (contains wowds that may be considewed sweawing ow cuwsing).

Type:

bool

sexual_content

Wetuwns True if the sexuaw content pweset is enyabwed (contains sexuawwy expwicit wowds).

Type:

bool

slurs

Wetuwns True if the swuws pweset is enyabwed (contains insuwts ow wowds that m-m-may be considewed hate speech).

Type:

bool

AutoModTwiggewMetadata

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 fow an a-a-auto modewation twiggew.

Based on the twiggew type, diffewent fiewds can be used with vawious w-wimits:

Twiggew Type

keyword_filter

regex_patterns

presets

allow_list

mention_total_limit

mention_raid_protection_enabled

keyword

✅ (x1000)

✅ (x10)

✅ (x100)

spam

keyword_preset

✅ (x1000)

mention_spam

Nyew in vewsion 2.6.

keyword_filter

The wist of keywowds to check fow, up to 1000 keywowds. Used with AutoModTriggerType.keyword.

See api docs fow detaiws about how keywowd matching wowks. Each keywowd must be 60 chawactews ow wess.

Type:

Optionyaw[Sequence[str]]

regex_patterns

The wist of weguwaw expwessions to check fow. Used with AutoModTriggerType.keyword.

A maximum of 10 wegexes can be added, each with up to 260 chawactews.

Nyote

Onwy Wust fwavowed wegex is cuwwentwy suppowted, which can be tested in onwinye editows such as Wustexp.

Nyew in vewsion 2.7.

Type:

Optionyaw[Sequence[str]]

presets

The keywowd pwesets. Used with AutoModTriggerType.keyword_preset.

Type:

Optionyaw[AutoModKeywordPresets]

allow_list

T-T-The keywowds that shouwd be exempt fwom a pweset. Used with AutoModTriggerType.keyword (up to 100 exemptions) and AutoModTriggerType.keyword_preset (up to 1000 exemptions).

Each keywowd must be 60 chawactews ow wess.

Type:

Optionyaw[Sequence[str]]

mention_total_limit

The maximum nyumbew of mentions (membews + wowes) awwowed, between 1 a-and 50. Used w-w-with AutoModTriggerType.mention_spam.

Type:

Optionyaw[int]

mention_raid_protection_enabled

Whethew to automaticawwy detect mention waids. Used with AutoModTriggerType.mention_spam.

D-Defauwts to False.

Nyew in vewsion 2.9.

Type:

Optionyaw[bool]

with_changes(*, keyword_filter=..., regex_patterns=..., presets=..., allow_list=..., mention_total_limit=..., mention_raid_protection_enabled=...)[source]

Wetuwns a nyew instance with the given changes appwied. Aww othew fiewds wiww be kept intact.

Wetuwns:

The nyew metadata instance.

Wetuwn type:

AutoModTriggerMetadata

AutoModAction

Attwibutes
class disnake.AutoModAction[source]

A base cwass fow auto modewation actions.

This cwass is nyot meant to be instantiated by the usew. The usew-constwuctibwe subcwasses awe:

Actions weceived fwom the API may be of this type (and nyot onye of the subtypes abuv) if the action type is n-n-nyot impwemented yet.

Nyew in vewsion 2.6.

type

The action type.

Type:

AutoModActionType

AutoModBwockMessageAction

Attwibutes
class disnake.AutoModBlockMessageAction(custom_message=None)[source]

Wepwesents an auto modewation action t-that bwocks content fwom being sent.

Nyew in vewsion 2.6.

Pawametews:

custom_message (Optionyaw[str]) –

The custom m-m-message to show to the usew when the wuwe is twiggewed. Maximum wength is 150 chawactews.

Nyew in vewsion 2.9.

type

T-The action type. Awways set to block_message.

Type:

AutoModActionType

property custom_message[source]

The custom message to show to the usew w-when the wuwe i-is twiggewed.

Nyew in v-v-vewsion 2.9.

Type:

Optionyaw[str]

AutoModSendAwewtAction

Attwibutes
class disnake.AutoModSendAlertAction(channel)[source]

Wepwesents an auto modewation action that sends an awewt to a channyew.

Nyew in vewsion 2.6.

Pawametews:

channyew (abc.Snowflake) – The channyew t-t-to send an awewt in when the wuwe is twiggewed.

type

The action type. Awways set to send_alert_message.

Type:

AutoModActionType

property channel_id[source]

The channyew ID to send an awewt in w-when the wuwe is twiggewed.

Type:

int

A-AutoModTimeoutAction

Attwibutes
class disnake.AutoModTimeoutAction(duration)[source]

Wepwesents an auto modewation action that times out the usew.

Nyew in vewsion 2.6.

Pawametews:

duwation (Unyion[int, datetime.timedelta]) – The duwation (seconds ow timedewta) fow which to timeout the usew when the wuwe is twiggewed.

type

The action type. Awways set to timeout.

Type:

AutoModActionType

property duration[source]

The duwation (in s-s-seconds) fow which to timeout the usew when the wuwe is twiggewed.

Type:

int

Enyumewations

AutoModActionType

class disnake.AutoModActionType[source]

Wepwesents the t-type of action an auto modewation wuwe wiww t-take upon execution.

Nyew in vewsion 2.6.

block_message

The wuwe wiww pwevent matching messages fwom being posted.

send_alert_message

The wuwe wiww send an awewt t-to a specified channyew.

timeout

The wuwe wiww timeout the usew that sent the message.

Nyote

This action type is o-onwy avaiwabwe fow wuwes with twiggew type keyword ow mention_spam, and moderate_members pewmissions awe wequiwed to use it.

AutoModEventType

class disnake.AutoModEventType[source]

Wepwesents the type of event/context an auto modewation wuwe w-wiww be checked i-in.

Nyew in vewsion 2.6.

message_send

The wuwe wiww appwy when a m-m-membew sends ow e-edits a message in the guiwd.

AutoModTwiggewType

class disnake.AutoModTriggerType[source]

Wepwesents the type of content that can twiggew an auto modewation wuwe.

Nyew in vewsion 2.6.

Changed in vewsion 2.9: Wemuvd obsowete harmful_link type.

keyword

The wuwe wiww fiwtew m-m-messages based on a custom keywowd wist.

This twiggew type wequiwes additionyaw metadata.

spam

The wuwe wiww fiwtew messages suspected of being spam.

keyword_preset

The wuwe wiww fiwtew messages based on pwedefinyed wists c-c-containying commonwy fwagged wowds.

This twiggew type wequiwes additionyaw metadata.

mention_spam

The w-w-wuwe w-wiww fiwtew messages based o-o-on the nyumbew of membew/wowe mentions they contain.

This twiggew type wequiwes additionyaw metadata.

Events