# Trap channel

Source: https://righteousbot.dev/docs/protection/trap-channel/

Set up a channel nobody should post in, and punish the self-bots and spam accounts that do.

A trap channel holds a standing warning and nothing else. Members read it and leave. Spam accounts that
post in every channel they find get punished at once. Every [`,trap`](/commands/server-tools/trap/#trap)
command needs **Manage Server**.

## Set up the trap [#set-up-the-trap]

[`,trap setup`](/commands/server-tools/trap/#trap-setup) makes a channel (needs Manage Channels) or
adopts one you name. Leave it visible: a trap nobody can see catches nothing. Threads inside it count
as part of the trap.

<CommandBlock syntax=",trap setup [#channel]" example=",trap setup #do-not-post" />

Then whitelist anyone who must post there with
[`,trap whitelist`](/commands/server-tools/trap/#trap-whitelist), and check everything with
[`,trap settings`](/commands/server-tools/trap/#trap-settings).

<CommandBlock syntax=",trap whitelist <add|remove|list> [@role|@user]" example=",trap whitelist add @Staff" />

<Callout type="warn" title="Staff are not immune">
  Only the server owner, the bot owner and whitelisted users and roles are immune. An unwhitelisted Administrator is
  punished like anyone else, and their own `,trap` commands are deleted inside a trap channel before they
  run. Configure it from another channel, or whitelist your staff role.
</Callout>

## Choose the punishment [#choose-the-punishment]

[`,trap action`](/commands/server-tools/trap/#trap-action) sets it; the default is `softban`.

<CommandBlock syntax=",trap action <softban|ban|kick|timeout|mute|jail> [duration]" example=",trap action timeout 2h" />

| Action    | Bot needs        | Effect                                                                     |
| --------- | ---------------- | -------------------------------------------------------------------------- |
| `softban` | Ban Members      | Bans with a message purge, then unbans                                     |
| `ban`     | Ban Members      | Permanent                                                                  |
| `kick`    | Kick Members     | They can rejoin                                                            |
| `timeout` | Moderate Members | One hour unless you give a duration                                        |
| `mute`    | Manage Roles     | Needs [`,config muterole`](/commands/server-tools/config/#config-muterole) |
| `jail`    | Manage Roles     | Needs [`,config jailrole`](/commands/server-tools/config/#config-jailrole) |

The caught message is deleted first and skips your snipe cache and delete logs. One trap embed goes to the [`,config logchannel`](/commands/server-tools/config/#config-logchannel).

## Punish repeat offenders harder [#punish-repeat-offenders-harder]

[`,trap escalation`](/commands/server-tools/trap/#trap-escalation) punishes a second catch harder. Off
by default; the escalation action is `ban` unless you name another. Counts come from punishment history,
so [`,punishmenthistory clear`](/commands/moderation/punishmenthistory/#punishmenthistory-clear) resets
them and [`,punishmenthistory remove`](/commands/moderation/punishmenthistory/#punishmenthistory-remove) on a trap
case takes one off.

<CommandBlock syntax=",trap escalation <on|off> [action]" example=",trap escalation on ban" />

[`,trap joingate`](/commands/server-tools/trap/#trap-joingate) uses the escalation action on a *first*
catch when the account or membership is under 1 to 90 days old (default 7). Off by default. It uses the
escalation action even with escalation off, so `,trap escalation off timeout` softens it.

<CommandBlock syntax=",trap joingate <on|off> [days]" example=",trap joingate on 7" />

## Restyle the warning [#restyle-the-warning]

[`,trap counter`](/commands/server-tools/trap/#trap-counter) shows or hides the embed and its count
(`off` is a silent trap). [`,trap embed`](/commands/server-tools/trap/#trap-embed) changes how it
looks: `view` returns the code your server runs, `set` replaces it, `remove` restores the default, and
`resend` posts a fresh one. Hiding the counter keeps your code; setting a code doesn't turn the counter on.

<CommandBlock syntax=",trap counter <on|off|reset|set> [count]" example=",trap counter set 42" />

<CommandBlock syntax=",trap embed <view|set|remove|resend> [code]" example=",trap embed set {color: #FF4747}$p{title: 🪤 Do not post here}$p{description: This channel is a trap. Anyone who posts is punished automatically: **{trap.action}**, no warning. Caught so far: **{trap.counter}**.}$p{footer: {guild.name} && {guild.icon}}" />

<DiscordEmbed
  caption="The default warning, with softban, escalation off and 42 catches so far. `,trap embed view` hands back its code."
  color="#FF4747"
  title="🪤 DO NOT SEND MESSAGES IN THIS CHANNEL"
  description="This channel is a trap for spam bots. Anyone who posts here is punished automatically — no warning."
  fields="[
  { name: &#x22;⚖️ Punishment&#x22;, value: &#x22;**a softban**&#x22;, inline: true },
  { name: &#x22;🤖 Caught&#x22;, value: &#x22;**42**&#x22;, inline: true },
]"
  footer="Righteous • whitelisted roles are exempt"
/>

Trap tokens: `{trap.counter}` (accounts caught), `{trap.action}` (punishment, written out), `{trap.channel}` (`#name`) and `{trap.escalation}` (the escalation punishment, or nothing when off).

<Callout type="warn" title="Two things that silently go wrong">
  Nobody triggered the standing embed, so `{user}`, `{user.mention}` and `{user.avatar}` mean the bot
  here. And `{trap.escalation}` is empty while escalation is off, so `**{trap.escalation}**` posts a
  field of `****`. The default adds that field only when escalation is on.
</Callout>

The warning must render an embed: `{v2:}` is refused on save, and `{content:}`, `{button:}`,
`{gallery:}`, `{section:}` and `{separator:}` produce nothing. See [Embed codes](/docs/features/embed-codes/).

## Tell the caught account what happened [#tell-the-caught-account-what-happened]

[`,trap dm`](/commands/server-tools/trap/#trap-dm) controls the DM a caught account gets (on by
default). It is sent before a ban or kick, the only moment it can still arrive.

<CommandBlock syntax=",trap dm <on|off> | invite <on|off> | embed <code|check|reset>" example=",trap dm invite on" />

For your own wording, `,trap dm embed <code>`. Here `{user}` is the caught account, and `{action}` is a
whole phrase ("softbanned (...)") naming the punishment that landed, so an escalated catch says "banned".
`{trap.counter}`, `{trap.action}` and `{trap.escalation}` don't work in a DM and post as literal text. A
DM code may use plain text, buttons and Components V2; `++delete` is accepted and ignored.

<Callout type="warn" title="The preview is not the DM">
  The reply you get on save shows `{action}` as the bare word (`softban`), `{trap.channel}` as your
  primary trap, `{user}` as you, and no rejoin invite. The real DM differs on all four. Only a real
  catch shows it.
</Callout>

<Callout type="warn" title="The rejoin invite reaches softban and kick DMs only">
  Under `ban`, `timeout`, `mute` or `jail`, `invite on` saves and does nothing. The bot also needs a
  non-trap channel where it may create an invite, or even a softban DM goes out without one. It is
  appended to your code, so never write one yourself.
</Callout>

## Run more than one trap [#run-more-than-one-trap]

[`,trap channels`](/commands/server-tools/trap/#trap-channels) adds up to five, each with its own
embed; the catch count is shared. The setup channel is primary and can't be removed: re-run
`,trap setup` to change it, which resets the list.
[`,trap randomize`](/commands/server-tools/trap/#trap-randomize) renames them every 1 to 168 hours
(default 24, off by default, needs Manage Channels) so the name can't be learned. Channels the bot can't
rename are left alone.

<CommandBlock syntax=",trap channels <add|remove|list> [#channel]" example=",trap channels add #do-not-post-2" />

<CommandBlock syntax=",trap randomize <on|off> [hours]" example=",trap randomize on 24" />

## Review and remove [#review-and-remove]

[`,trap stats`](/commands/server-tools/trap/#trap-stats) reports totals by action, unique accounts,
repeats and the busiest days. [`,trap disable`](/commands/server-tools/trap/#trap-disable) removes the trap.

<CommandBlock syntax=",trap stats" />

## Common issues [#common-issues]

**A moderator got banned by the trap.** Whitelist them or their role with `,trap whitelist add`.
Permissions never grant immunity.

**My `,trap` command did nothing.** You ran it inside a trap channel without being owner or whitelisted,
so it was deleted unread. Run it elsewhere.

**Someone posted and nothing happened.** The punishment failed: a missing permission, a member above the
bot, or no mute or jail role. The failure goes to your [log channel](/commands/server-tools/config/#config-logchannel), and with none
set the bot posts nothing and says nothing, so set one first. The message is deleted either way.

**The warning embed disappeared.** Run `,trap embed resend`.
