AutoModerationRule

Auto moderation feature which allows guilds to set rules that trigger based on some criteria.

Attributes

actions : None, tuple of AutoModerationAction

Actions which will execute when the rule is triggered. Defaults to 0.

creator_id : int

The user who created the rule. Defaults to 0.

enabled : bool

Whether the rule is enabled.

For which events is the rule applied.

excluded_channel_ids : None, tuple of int

The excluded channels' identifiers.

excluded_role_ids : None, tuple of int

The excluded roles' identifiers.

guild_id : int

The guild's identifier where the rule is. Defaults to 0.

id : int

The unique identifier of the auto moderation rule. Defaults to 0.

name : str

The rule's name.

Trigger type specific metadata if applicable.

Characterizes the type of content which can trigger the rule.

Properties

created_at

When the entity was created.

Returns

created_at : datetime

creator

Returns who created the auto moderation rule.

Returns

creator : ClientUserBase

excluded_channels

Returns the excluded channels from the rule.

Returns

excluded_channels : None, tuple of Channel

excluded_roles

Returns the excluded roles from the rule.

Returns

excluded_roles : None, tuple of Role

guild

Returns the auto moderation rule's guild. If the guild is not cached returns None

Returns

guild : None, Guild

partial

Returns whether the auto moderation rule is partial.

Returns

partial : bool

Methods

__new__(...)

Creates a new auto moderation rule with the given parameters.

ParameterTypeOptionalKeyword onlyDescription
name

str

The rule's name.

actions

None, AutoModerationAction, iterable of AutoModerationAction

Actions which will execute when the rule is triggered.

trigger_type

AutoModerationRuleTriggerType, int

Auto moderation trigger type.

enabled

bool

Whether the rule is enabled.

event_type

None, int, AutoModerationEventType

For which events is the rule applied.

excluded_channel_ids

None, int, Channel, iterable of (int, Channel)

Excluded channels from the rule.

excluded_role_ids

None, int, Role, iterable of (int, Role)

Excluded roles from the rule.

**keyword_parameters

Keyword parameters

Additional keyword parameters defining how the rule is triggered.

excluded_keywords

None, str, iterable of str

Excluded keywords from preset filter.

keyword_presets

None, int, AutoModerationKeywordPresetType, iterable of (int, AutoModerationKeywordPresetType)

Keyword preset defined by Discord which will be searched for in content.

keywords

None, str, iterable of str

Substrings which will be searched for in content.

mention_limit

None, int

The amount of mentions in a message after the rule is triggered.

regex_patterns

None, tuple of str

Regular expression patterns which are matched against content.

Raises

TypeError

  • If a parameter's type is incorrect.

ValueError

  • If a parameter's value is incorrect.

copy()

Copies the auto moderation rule returning a new partial one.

Returns

new : AutoModerationRule

copy_with(...)

Copies the auto moderation rule with the given attributes replaced.

ParameterTypeOptionalKeyword onlyDescription
actions

None, AutoModerationAction, iterable of AutoModerationAction

Actions which will execute when the rule is triggered.

enabled

bool

Whether the rule is enabled.

event_type

None, int, AutoModerationEventType

For which events is the rule applied.

excluded_channel_ids

None, int, Channel, iterable of (int, Channel)

Excluded channels from the rule.

excluded_role_ids

None, int, Role, iterable of (int, Role)

Excluded roles from the rule.

name

str

The rule's name.

trigger_type

AutoModerationRuleTriggerType, int

Auto moderation trigger type.

**keyword_parameters

Keyword parameters

Additional keyword parameters defining how the rule is triggered.

excluded_keywords

None, str, iterable of str

Excluded keywords from preset filter.

keyword_presets

None, int, AutoModerationKeywordPresetType, iterable of (int, AutoModerationKeywordPresetType)

Keyword preset defined by Discord which will be searched for in content.

keywords

None, str, iterable of str

Substrings which will be searched for in content.

mention_limit

None, int

The amount of mentions in a message after the rule is triggered.

regex_patterns

None, tuple of str

Regular expression patterns which are matched against content.

Returns

new : AutoModerationRule

Raises

TypeError

  • If a parameter's type is incorrect.

ValueError

  • If a parameter's value is incorrect.

from_data(data)

Creates a new AutoModerationRule from the given data.

ParameterTypeDescription
data

dict of (str, object) items

Received auto moderation rule data.

Returns

self : AutoModerationRule

The created auto moderation rule.

iter_actions()

Iterates over the actions of the auto moderation rule.

This method is an iterable generator.

Yields

action : AutoModerationAction

iter_excluded_channel_ids()

Iterates over the excluded channel identifiers from the rule.

This method is an iterable generator.

Yields

excluded_channel_id : int

iter_excluded_channels()

Iterates over the excluded channels from the rule.

This method is an iterable generator.

Yields

excluded_channel : Channel

iter_excluded_role_ids()

Iterates over the excluded role identifiers from the rule.

This method is an iterable generator.

Yields

excluded_role_id : int

iter_excluded_roles()

Iterates over the excluded roles from the rule.

This method is an iterable generator.

Yields

excluded_role : Role

precreate(rule_id, ...)

Precreates the auto moderation rule by creating a new one if not yet exists of the given identifier.

ParameterTypeOptionalKeyword onlyDescription
rule_id

int

The auto moderation rule's identifier.

*keyword_parameters

Keyword parameters

Keyword parameters defining how should the rule's attributes be set.

actions

None, AutoModerationAction, iterable of AutoModerationAction

Actions which will execute when the rule is triggered.

creator_id

int, ClientUserBase

The user who created the rule.

enabled

bool

Whether the rule is enabled.

event_type

None, int, AutoModerationEventType

For which events is the rule applied.

excluded_channel_ids

None, int, Channel, iterable of (int, Channel)

Excluded channels from the rule.

excluded_role_ids

None, int, Role, iterable of (int, Role)

Excluded roles from the rule.

guild_id

int, Guild

The guild's identifier where the rule is.

name

str

The rule's name.

trigger_type

AutoModerationRuleTriggerType, int

Auto moderation trigger type.

excluded_keywords

None, str, iterable of str

Excluded keywords from preset filter.

keyword_presets

None, int, AutoModerationKeywordPresetType, iterable of (int, AutoModerationKeywordPresetType)

Keyword preset defined by Discord which will be searched for in content.

keywords

None, str, iterable of str

Substrings which will be searched for in content.

mention_limit

None, int

The amount of mentions in a message after the rule is triggered.

regex_patterns

None, tuple of str

Regular expression patterns which are matched against content.

Returns

self : instance<cls>

Raises

TypeError

  • If a parameter's type is incorrect.
  • Extra or unused parameters given.

ValueError

  • If a parameter's value is incorrect.

to_data(...)

Converts the auto moderation rule to a json serializable object.

ParameterTypeOptionalKeyword onlyDefaultDescription
defaults

bool

False

Whether default values should be included as well.

include_internals

bool

False

Whether internal fields should be included.

Returns

data : dict of (str, object) items

_create_empty(rule_id)

Creates an auto moderation rule with it's attributes set as their default values.

ParameterTypeDescription
rule_id

int

The auto moderation rule's identifier.

Returns

self : instance<cls>

_difference_update_attributes(data)

Updates the auto moderation rule and returns the changed attributes in a dictionary with the changed attributes in a attribute-name, old-value relation.

ParameterTypeDescription
data

dict of (str, object) items

Received guild profile data.

Returns

old_attributes : dict of (str, object) items

All item in the returned dict is optional.

Might contain the following items:

KeysValues
actionsNone, tuple of AutoModerationAction
enabledbool
event_typeAutoModerationEventType
excluded_channel_idsNone, tuple of int
excluded_role_idsNone, tuple of int
namestr
trigger_metadataAutoModerationRuleTriggerMetadataBase
trigger_typeAutoModerationRuleTriggerType

_set_attributes(data)

Sets the auto moderation rule's attributes (excluding .id).

ParameterTypeDescription
data

dict of (str, object) items

Received guild profile data.

_update_attributes(data)

Updates the auto moderation rule with overwriting it's old attributes.

ParameterTypeDescription
data

dict of (str, object) items

Received guild profile data.

__eq__()

Returns whether the two auto moderation rules are equal.

__ge__()

Whether this entity's id is greater or equal than the other's.

__getattr__()

Drops a rich attribute error.

__gt__()

Whether this entity's id is greater than the other's.

__hash__()

Returns the auto moderation rule's hash value.

__le__()

Whether this entity's id is less or equal than the other's.

__lt__()

Whether this entity's id is less than the other's.

__ne__()

Returns whether the two auto moderation rules are not equal.

__repr__()

Returns the auto moderation rule's representation