Managing rules
guideList a guild's AutoMod rules, edit them live, delete them, and react when one fires.
This page covers the rules that already exist on a guild, whether a script or a moderator made them: reading them, changing them, deleting them, and the event that fires when one acts. You're assumed to have a bot named "my-bot" logged in with Manage Server, and to know the three await rules.
Reading a guild's rules
automod rules of %guild% lists every rule of a guild, and automod rule with id %string% in %guild% fetches one. DiSky keeps no AutoMod cache, so both ask Discord and both require await.
on message received seen by "my-bot": if discord content of event-message is "!rules": await set {_rules::*} to automod rules of event-guild loop {_rules::*}: reply with "%name of loop-value%: %automod trigger type of loop-value%, enabled %enabled of loop-value%"
What you get is a snapshot taken at that moment. Read a rule again after editing it to see the new state.
Property | Returns |
|---|---|
the rule's name | |
whether the rule is enforced | |
| |
| |
the keyword trigger's lists | |
the preset trigger's lists | |
the mention spam trigger's settings | |
who and where the rule ignores | |
what the rule does | |
who created it |
[the] automod rules of %guild%All AutoMod rules of the guild. Fetched online, so it requires 'await'.Editing a rule
name, enabled, exempt roles, exempt channels, automod responses and trigger config are writable on a rule. Every change is sent to Discord at once; put await in front to wait for it before the next line reads the rule again.
on message received seen by "my-bot": if discord content of event-message is "!pause-rules": await set {_rules::*} to automod rules of event-guild loop {_rules::*}: await set enabled of loop-value to false await add event-channel to exempt channels of loop-value
add and remove start from the rule as it was read. One add a and b to ... line sends both values together, but two separate add lines on the same snapshot each start from that snapshot, so only the second one survives: read the rule again between them.
trigger config replaces what the rule looks for. It is write-only (read the keyword, preset and mention properties instead), and the new trigger must be of the rule's kind: a keyword rule takes a keyword or pattern trigger, never a preset one.
set {_t} to a new automod keyword trigger with the keywords "newword" await set trigger config of {_rule} to {_t}
[the] exempt roles of %automodrule%The roles whose members are ignored by the rule (20 max).Deleting a rule
destroy deletes a rule.
on message received seen by "my-bot": if discord content of event-message is "!drop-rule": await set {_rule} to automod rule with id "000000000000000000" in event-guild destroy {_rule}
A community guild must keep its mention spam rule: Discord refuses to delete it. Disable it with set enabled of {_rule} to false instead.
When a rule fires
on automod execution fires once per response a rule takes: a rule that blocks the message and sends an alert fires it twice. The bot needs the auto_moderation_execution intent for it.
on automod execution seen by "my-bot": send "%event-user% triggered %automod rule id of event-automod% in %event-channel%" to console send "matched '%matched keyword of event-automod%' in: %automod message content of event-automod%" to console
event-automod carries what was matched. matched keyword and matched content say what set the rule off, automod message content is the whole message (empty without the message_content intent), and event-automodresponse is the response being run.
[discord] automod (execution|execute)Fired when an automated automod response has been triggered through an automod Rule. Can be used to get the channel, user content, keyword that was found, the automod response and the id of the automod rule, the user, the id of the message which triggered the rule, the guild it occurred in, and the id of the alert message sent to the alert channel (if configured).Errors you may see
Message (console) | Cause | Fix |
|---|---|---|
requires 'await' (parse error) |
| Put |
[50035] Invalid Form Body naming the trigger |
| Use a trigger of the rule's kind |
A Discord error when deleting a mention spam rule | The guild is a community guild | Disable the rule instead |