# Rules

URL: https://zerodev.ca/docs/advanced-automod/usage

> Write rules, choose actions, send responses and set up the honeypot.



Advanced Automod checks every new and edited message in your main server against each enabled rule, in order. When a rule triggers, its actions run one after another, then its response is sent.

## Example Rules

### Emoji Spam

Delete messages with more than 8 emojis and mute for a minute. Server emojis you want people to spam are ignored.

```json5
emoji_spam: {
  name: "Emoji Spam",
  enabled: true,
  management: {
    type: "emoji",
    action: [{ type: "delete" }, { type: "mute", duration: "1m" }],
    guide: { emoji_limit: 8, ignored_emojis: ["<:hype:123456789012345678>"] },
  },
},
```

### Mass Pings

Pinging more than 5 people within 30 seconds deletes all of those messages, mutes for 10 minutes and adds a warning. Your staff role is not counted, so members can still ping for help.

```json5
mass_pings: {
  name: "Mass Pings",
  enabled: true,
  management: {
    type: "ping",
    action: [{ type: "delete" }, { type: "mute", duration: "10m" }, { type: "warn", reason: "Mass pinging" }],
    guide: { ping_limit: 5, window_ms: 30000, ignored_pings: ["STAFF_ROLE_ID"] },
  },
},
```

The ping rule counts across messages. Five messages with one ping each trigger it just like one message with five.

### Banned Words and Links

Delete invite links and a list of words, and ban repeat scammers by hand from the logs.

```json5
invites_and_words: {
  name: "Invites and Banned Words",
  enabled: true,
  management: {
    type: "message",
    action: [{ type: "delete" }, { type: "warn" }],
    guide: {
      messages: ["free nitro", "steamcommunity.ru"],
      regex: "discord(\\.gg|app\\.com/invite|\\.com/invite)/\\w+",
    },
  },
},
```

`messages` matches anywhere in the text, so `"ass"` also matches "class". Use `regex` with `\\b` word boundaries when that matters. Backslashes must be doubled in the config file.

## Responses

A response tells the member why their message was removed. Responses live in `configuration/advancedmod-lang.json5`:

1. Add an entry under `responses`, such as `excessive_emojis`. See [the lang file](/docs/advanced-automod/configuration#advancedmod-langjson5).
2. Point the rule at it:

```json5
response: {
  type: "DM",
  message: {
    id: "excessive_emojis",
    buttons: {
      name: "Details",
      style: "GRAY",
      message: {
        id: "excessive_emojis_details",
        buttons: { name: "Go Back", style: "GRAY", backbutton: true },
      },
    },
  },
},
```

The member gets `excessive_emojis` with a **Details** button. Pressing it swaps in `excessive_emojis_details`, which has a **Go Back** button to return. Placeholders like `%rule%` and `%channel%` keep working as the member moves between them.

If the ID is missing from the lang file, the console logs `Response "<id>" not found in advancedmod-lang.json5.` and nothing is sent. Members with DMs closed will not get `DM` responses, and the console logs `Could not DM <user>`. `REPLY` replies to the message in the channel, so it only works when the rule does not also `delete` it.

## Honeypot

The honeypot is a channel that real members have no reason to post in. Scam bots that post in every channel get caught.

1. Create a channel, such as `#do-not-post`, with a clear warning in its topic.
2. Run `/setup` and set it as the `honeypot` channel.
3. Set `honeypot_mute_hours` in the config.

Anyone who posts there has their message deleted and is muted for `honeypot_mute_hours`. Members in `ignored.users`, `ignored.roles` or the moderation whitelist are skipped. No other rules run on that channel.

## Ignoring Channels and Staff

Add staff roles to `ignored.roles` so they are never caught. Add channels such as `#memes` to `ignored.channels`, or a whole category to `ignored.categories`, to switch rules off there.

## Troubleshooting

| Problem                 | Fix                                                                                                                                      |
| ----------------------- | ---------------------------------------------------------------------------------------------------------------------------------------- |
| Nothing is caught       | The plugin only checks your main server, the one set as `discord_guild_id` in AthenaBot. Check the member is not ignored or whitelisted. |
| Mute, kick or ban fails | AthenaBot's role must be above the member's highest role. The console says `Failed to mute ...` with the reason.                         |
| A regex never matches   | Check the console for a regex error, and remember to double backslashes.                                                                 |
