# Message filters

Source: https://righteousbot.dev/docs/protection/message-filters/

Block links, invites, banned words, music files and mass pings, and choose what happens to the sender.

Filters delete messages and can punish the sender. Links, invites, music files, mass mentions and
image-only are set **per channel**; the banned-word list covers the **whole server**. Every
[`,filter`](/commands/server-tools/filter/#filter) command needs **Manage Messages**.

## Block something in a channel [#block-something-in-a-channel]

Turn a filter on for one channel or `all`, and off the same way. `++punish` is optional.

<CommandBlock syntax=",filter <type> <on|off> <#channel|all> [++punish <punishment>]" example=",filter links on #general ++punish mute" />

| Filter        | Command                                                            | Deletes                                                                             |
| ------------- | ------------------------------------------------------------------ | ----------------------------------------------------------------------------------- |
| Links         | [`,filter links`](/commands/server-tools/filter/#filter-link)      | any message with a link                                                             |
| Invites       | [`,filter invites`](/commands/server-tools/filter/#filter-invite)  | invites to other servers (your own is allowed)                                      |
| Music files   | [`,filter mp3`](/commands/server-tools/filter/#filter-mp3)         | attachments ending `.mp3`, `.wav`, `.m4a`, `.flac`, `.ogg`, `.aac`, `.wma`, `.opus` |
| Mass mentions | [`,filter mention`](/commands/server-tools/filter/#filter-mention) | messages pinging at least `++threshold <number>` people                             |
| Image only    | [`,filter words`](/commands/server-tools/filter/#filter-word)      | any message with no attachment                                                      |

<Callout type="warn" title="filter words is the image-only filter">
  `,filter words on #media` deletes everything posted there without an attachment. The banned-word list
  is [`,filter add`](/commands/server-tools/filter/#filter-add).
</Callout>

<Callout type="warn" title="The music filter reads the filename, not the file">
  Rename a track to `song.png` and it passes; an image called `cover.mp3` is deleted. It deters, it does
  not inspect.
</Callout>

[`,filter type`](/commands/server-tools/filter/#filter-type) shows which filters are on, and where.

## Ban a word across the server [#ban-a-word-across-the-server]

[`,filter add`](/commands/server-tools/filter/#filter-add) takes a word of two or more characters and
an optional punishment. With none, the message is just deleted. Edited messages are re-checked.

<CommandBlock syntax=",filter add <word> [punishment] [++exact]" example=",filter add ass ban ++exact" />

A word matches anywhere inside a message, so `ass` also catches "class". `++exact` stops that, per
word (`/filter add` has an `exact` option). Manage the list with [`remove`](/commands/server-tools/filter/#filter-remove),
[`list`](/commands/server-tools/filter/#filter-list) and [`clear`](/commands/server-tools/filter/#filter-clear).

<Callout type="warn" title="Exact is not an obfuscation filter">
  "l o s e r" and "l0ser" get past `loser` whether `++exact` is on or off. Add each spelling as its own
  word.
</Callout>

## Choose what happens to the sender [#choose-what-happens-to-the-sender]

Every filter deletes the message. The punishment is on top, and optional. A message that breaks three
rules is punished once.

| Punishment   | Bot needs                                                                                         |
| ------------ | ------------------------------------------------------------------------------------------------- |
| none         | nothing, the message is only deleted                                                              |
| `warn`       | nothing                                                                                           |
| `mute`       | Manage Roles and a role from [`,config muterole`](/commands/server-tools/config/#config-muterole) |
| `jail`       | Manage Roles and a role from [`,config jailrole`](/commands/server-tools/config/#config-jailrole) |
| `stripstaff` | Manage Roles and a list from [`,staff add <role>`](/commands/server-tools/staff/#staff-add)       |
| `kick`       | Kick Members                                                                                      |
| `ban`        | Ban Members                                                                                       |

## Exempt the people who should be [#exempt-the-people-who-should-be]

[`,filter whitelist`](/commands/server-tools/filter/#filter-whitelist) exempts a user, a role, or your
whole staff list. List kinds after the target to scope it; leave them off and it bypasses everything.

<CommandBlock syntax=",filter whitelist <add|remove|scope|list|clear|on|off> [user|role|staff] [kind ...]" example=",filter whitelist add @Staff links invites" />

| Action          | Does                                                                                                                                         |
| --------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
| `add`, `remove` | Adds or removes the target                                                                                                                   |
| `scope`         | Changes what an existing entry bypasses. Refuses if the target isn't whitelisted yet. An entry added with no kinds bypasses **every** filter |
| `list`, `clear` | Shows every entry, or removes them all                                                                                                       |
| `on`, `off`     | Suspends every entry without deleting any                                                                                                    |

Kinds: `words`, `links`, `invites`, `mp3`, `mentions`, `imageonly` and `spam`. `spam` is
[flood protection](/docs/protection/flood-protection/), which reads this same whitelist.

`staff` is a reserved word that follows the live [`,staff`](/commands/server-tools/staff/#staff-add)
list, so adding or removing a staff role updates the exemption by itself. It wins over a role named
Staff; mention the role (`@Staff`) to whitelist the role itself. [Staff roles](/docs/features/staff-roles/) covers the list.

<Callout type="warn" title="Moderators are filtered like everyone else">
  Holding Manage Messages exempts nobody. Only the bot owner, the server owner, and whitelisted users
  and roles are exempt. For staff to post links in a filtered channel, whitelist the staff role.
</Callout>

## Check what a message would trip [#check-what-a-message-would-trip]

[`,filter test`](/commands/server-tools/filter/#filter-test) runs text through the channel's filters
and reports what would happen, deleting and punishing nothing. Mention a member to test as them,
including their whitelist exemptions.

<CommandBlock syntax=",filter test <text> [@member]" example=",filter test youre a loser @Nick" />

<DiscordEmbed
  caption="Testing as a member whose role is whitelisted for links only, in a channel with links, banned words and mass mentions filtered. The stripe takes your own role colour."
  invokedWith=",filter test youre a loser @Nick"
  color="#E91E63"
  title="Filter test"
  description="&#x22;Simulating **nick** in #general\n> youre a loser&#x22;"
  fields="[
  { name: &#x22;Links&#x22;, value: &#x22;No match (exempt anyway) — delete only\nno link found&#x22; },
  { name: &#x22;Banned words&#x22;, value: &#x22;WOULD TRIP — `mute`\nmatched \&#x22;loser\&#x22;&#x22; },
  { name: &#x22;Mass mentions&#x22;, value: &#x22;Not evaluated — `mute`\nnot evaluated — this simulator can't tell a real ping from the target mention above (threshold 5)&#x22; },
  { name: &#x22;Exemption&#x22;, value: &#x22;@Regulars (role) — Links&#x22; },
]"
/>

Music files and mass mentions can't be simulated from text: no verdict.

## Use the panel [#use-the-panel]

[`,filter panel`](/commands/server-tools/filter/#filter-panel) opens one menu for Overview, Channels,
Words, Whitelist and Punishments.

<Callout type="warn" title="The Channels picker replaces the whole list">
  Whatever you leave unselected turns off. Past 25 filtered channels the picker can't show the extras, so
  use **All off** to clear them rather than trusting an empty-looking picker.
</Callout>

## What the filters can't see [#what-the-filters-cant-see]

Forwarded messages and embed text (title, description, fields, footer) are checked as if typed.
[`,transcribe`](/commands/info/transcribe/#transcribe) redacts filtered words from a transcript but
never punishes, since a transcript is a guess.

<Callout type="warn" title="/translate is not covered">
  [`/translate`](/commands/info/translate/#translate) can read someone else's message back into the
  channel without redacting it. Turn it off in a strictly filtered channel.
</Callout>

## Common issues [#common-issues]

**A message was deleted but nobody was muted.** The mute or jail role is missing or deleted. Set it with
`,config muterole` or `,config jailrole`; the bot reports the failure in the channel and your moderation log.

**A channel emptied itself after `,filter words`.** That's the image-only filter. Run `,filter words off <#channel>`.

**Staff keep getting caught.** Run `,filter whitelist add staff` once. A permission alone never exempts anyone.

**The invite filter deletes invites to my own server.** The bot needs Manage Server to read your invite
list. Without it, it can't tell yours from anyone else's.
