DiSky DiSky v5.0.0-b1

Managing rules

guide

List a guild's AutoMod rules, edit them live, delete them, and react when one fires.

automodmoderationevents

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

lists every rule of a guild, and 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

message send or member update

keyword, spam, keyword preset, mention spam or member profile keyword

, ,

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

property automod rulesGuild[the] automod rules of %guild%All AutoMod rules of the guild. Fetched online, so it requires 'await'.list of AutoMod Rulesince 5.0.0-a2

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.

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}
property exempt rolesAutoMod Rule[the] exempt roles of %automodrule%The roles whose members are ignored by the rule (20 max).list of Rolesince 5.0.0-a2

Deleting a rule

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}
Some rules cannot be deleted

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

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. and say what set the rule off, is the whole message (empty without the message_content intent), and event-automodresponse is the response being run.

event AutoMod ExecutionEvents[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).since 5.0.0-a1

Errors you may see

Message (console)

Cause

Fix

requires 'await' (parse error)

automod rules of or automod rule with id was read without await

Put await in front of the line

[50035] Invalid Form Body naming the trigger

trigger config was set to a trigger of another kind

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

AutoMod Rule type 18 syntaxes A rule of Discord's AutoMod: what it looks for (its trigger), when it is checked and what it does. Read the rules of a guild with 'automod rules of %guild%' (requires await), then edit them through their properties; every change is sent to Discord immediately.
Was this page helpful?
An unhandled error has occurred. Reload 🗙

Rejoining the server...

Rejoin failed... trying again in seconds.

Failed to rejoin.
Please retry or reload the page.

The session has been paused by the server.

Failed to resume the session.
Please retry or reload the page.