#[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
Struct { .. } syntax; cannot be matched against without a wildcard ..; and struct update syntax will not work.name: CompactStringThe rule’s name.
event_type: EventTypeWhat the rule checks: sent messages, or member profiles for MemberProfile rules.
trigger_type: TriggerTypeHow the rule detects violations. Each guild may have up to 6 Keyword rules and 1 of
every other type.
trigger_metadata: TriggerMetadataThe 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
impl CreateAutoModerationRule
Sourcepub fn keyword(
name: impl Into<CompactString>,
keywords: impl IntoIterator<Item = impl Into<CompactString>>,
actions: impl IntoIterator<Item = Action>,
) -> Self
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.
Sourcepub fn spam(
name: impl Into<CompactString>,
actions: impl IntoIterator<Item = Action>,
) -> Self
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.
Sourcepub fn keyword_preset(
name: impl Into<CompactString>,
presets: impl IntoIterator<Item = KeywordPresetType>,
actions: impl IntoIterator<Item = Action>,
) -> Self
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.
Sourcepub fn mention_spam(
name: impl Into<CompactString>,
limit: u8,
actions: impl IntoIterator<Item = Action>,
) -> Self
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.
Sourcepub fn member_profile(
name: impl Into<CompactString>,
keywords: impl IntoIterator<Item = impl Into<CompactString>>,
actions: impl IntoIterator<Item = Action>,
) -> Self
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.