Skip to main content

CreateAutoModerationRule

Struct CreateAutoModerationRule 

Source
#[non_exhaustive]
pub struct CreateAutoModerationRule { pub name: CompactString, pub event_type: EventType, pub trigger_type: TriggerType, pub trigger_metadata: TriggerMetadata, pub actions: Vec<Action>, pub enabled: Option<bool>, pub exempt_roles: Vec<RoleId>, pub exempt_channels: Vec<ChannelId>, }
Expand description

The body of Create Auto Moderation Rule.

Built with one constructor per TriggerType (D-128), which sets the trigger, the EventType it checks and the trigger metadata it requires. The allow list, regular expressions, enabled and the exemptions are set through the public fields afterwards.

discord.js counterpart: the argument of AutoModerationRuleManager#create.

§Examples

use djs_model::{auto_moderation::Action, rest::CreateAutoModerationRule};

let mut body = CreateAutoModerationRule::keyword(
    "No spoilers",
    ["*spoiler*"],
    [Action::block_message()],
);
body.enabled = Some(true);
body.trigger_metadata.allow_list = vec!["spoilerfree".into()];
assert_eq!(
    serde_json::to_string(&body)?,
    r#"{"name":"No spoilers","event_type":1,"trigger_type":1,"trigger_metadata":{"keyword_filter":["*spoiler*"],"allow_list":["spoilerfree"]},"actions":[{"type":1}],"enabled":true}"#
);

Fields (Non-exhaustive)§

This struct is marked as non-exhaustive
Non-exhaustive structs could have additional fields added in future. Therefore, non-exhaustive structs cannot be constructed in external crates using the traditional Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.
§name: CompactString

The rule’s name.

§event_type: EventType

What the rule checks: sent messages, or member profiles for MemberProfile rules.

§trigger_type: TriggerType

How the rule detects violations. Each guild may have up to 6 Keyword rules and 1 of every other type.

§trigger_metadata: TriggerMetadata

The settings of the trigger; only the fields of trigger_type apply. Left out of the request when empty (Spam rules have none).

§actions: Vec<Action>

What happens when the rule triggers.

§enabled: Option<bool>

Whether the rule is enabled; Discord’s default is disabled.

§exempt_roles: Vec<RoleId>

Roles the rule does not apply to (up to 20).

§exempt_channels: Vec<ChannelId>

Channels the rule does not apply to (up to 50).

Implementations§

Source§

impl CreateAutoModerationRule

Source

pub fn keyword( name: impl Into<CompactString>, keywords: impl IntoIterator<Item = impl Into<CompactString>>, actions: impl IntoIterator<Item = Action>, ) -> Self

A rule that triggers on messages containing one of keywords (up to 1000, 60 characters each; * at the start or end matches a prefix or suffix). Add regex_patterns and an allow_list through trigger_metadata.

discord.js counterpart: AutoModerationRuleCreateOptions with AutoModerationRuleTriggerType.Keyword.

Source

pub fn spam( name: impl Into<CompactString>, actions: impl IntoIterator<Item = Action>, ) -> Self

A rule that triggers on messages Discord considers generic spam.

discord.js counterpart: AutoModerationRuleCreateOptions with AutoModerationRuleTriggerType.Spam.

Source

pub fn keyword_preset( name: impl Into<CompactString>, presets: impl IntoIterator<Item = KeywordPresetType>, actions: impl IntoIterator<Item = Action>, ) -> Self

A rule that triggers on messages containing words from Discord’s predefined word lists. Exceptions go into the allow_list (up to 1000).

discord.js counterpart: AutoModerationRuleCreateOptions with AutoModerationRuleTriggerType.KeywordPreset.

Source

pub fn mention_spam( name: impl Into<CompactString>, limit: u8, actions: impl IntoIterator<Item = Action>, ) -> Self

A rule that triggers on messages mentioning more than limit unique users and roles (up to 50). Enable mention_raid_protection_enabled to also detect mention raids.

discord.js counterpart: AutoModerationRuleCreateOptions with AutoModerationRuleTriggerType.MentionSpam.

Source

pub fn member_profile( name: impl Into<CompactString>, keywords: impl IntoIterator<Item = impl Into<CompactString>>, actions: impl IntoIterator<Item = Action>, ) -> Self

A rule that triggers when a member’s profile contains one of keywords, checked when they edit it. The keywords work as for keyword.

discord.js counterpart: AutoModerationRuleCreateOptions with AutoModerationRuleTriggerType.MemberProfile.

Trait Implementations§

Source§

impl Clone for CreateAutoModerationRule

Source§

fn clone(&self) -> Self

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Debug for CreateAutoModerationRule

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Eq for CreateAutoModerationRule

Source§

impl PartialEq for CreateAutoModerationRule

Source§

fn eq(&self, other: &Self) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl Serialize for CreateAutoModerationRule

Source§

fn serialize<__S>(&self, __serializer: __S) -> Result<__S::Ok, __S::Error>
where __S: Serializer,

Serialize this value into the given Serde serializer. Read more
Source§

impl StructuralPartialEq for CreateAutoModerationRule

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.