Catch spoilers without punishing people who actually hid them.
Shaw is a Discord spoiler bot I originally built for a Silksong community.
It watches selected channels for configured spoiler terms and removes messages when someone posts one openly.
The interesting part is what happens before that.
A term should be caught in normal text, but not because it appears inside a Discord spoiler tag, a URL, or another part of the message that Shaw has been told to leave alone.
What started as a basic word filter became mostly a problem of deciding when not to flag a match.
| Built for | A Silksong Discord community |
| Language | Python |
| Discord library | discord.py |
| Focus | Spoiler detection · false-positive avoidance · moderation tooling |
| Persistence | Local JSON |
| License | MIT |
The first version of Shaw sounded easy:
Keep a list of spoiler words. If a message contains one, delete it.
Then the false positives started.
Suppose Lace is configured as a spoiler term.
This should be caught:
I just found Lace
But this should not:
I just found ||Lace||
The second user has already used Discord's spoiler formatting correctly.
The same problem appears when a configured term occurs inside a URL or in Markdown content that Shaw has been told to protect.
So simply asking:
Does this message contain a banned word?
wasn't enough.
Shaw also needed to ask:
Where in the message did that word appear?
That became the main idea behind the project.
Before checking the configured spoiler vocabulary, Shaw identifies parts of the message that should not trigger a match.
Currently those include:
- Discord spoiler spans:
||hidden text|| - URLs
- visible text inside Markdown links
Each configured spoiler phrase is compiled into a case-insensitive regular expression with word boundaries.
When Shaw finds a possible match, it compares the position of that match against the protected parts of the message.
Message
│
├── find Discord spoiler spans
│
├── find URL spans
│
└── find protected Markdown link text
│
▼
Search for configured spoiler terms
│
▼
Where did the match occur?
│
├── inside protected text → ignore
│
└── exposed text → flag
The distinction is small, but it changes the behaviour significantly.
A normal word filter only cares whether a term appears.
Shaw also cares where it appears.
Assume Lace is in the configured spoiler list.
Lace appears later in the game
Result: flagged.
Correctly hidden spoiler
||Lace|| appears later in the game
Result: ignored.
https://example.com/lace
Result: ignored.
[Lace](https://example.com/page)Result: ignored.
The same configured term can therefore produce a different result depending on where it appears in the message.
That is the part of Shaw that turned out to be more interesting than the original spoiler-word list.
When Shaw finds an exposed configured term in one of the channels it monitors, it can:
- delete the original message;
- send the user a temporary warning;
- log the detected term for staff;
- increment that user's warning count;
- send an additional staff alert when the warning threshold is reached.
The warning sent back into the channel automatically disappears after a configurable amount of time so the bot does not replace spoiler messages with permanent moderation clutter.
Users with configured whitelisted roles can also be excluded from automatic checking.
Shaw keeps a warning count for users who repeatedly post unhidden spoilers.
For this project, the counts are persisted in a local JSON file rather than a database.
Updates to that shared state use an asynchronous lock so two warning updates do not modify the in-memory count at the same time.
Spoiler detected
│
▼
Acquire count lock
│
▼
Read current warning count
│
▼
Increment count
│
▼
Write JSON
│
▼
Release lock
When a user reaches the configured warning threshold, Shaw produces an additional staff log showing the user, their current count, and the moderation event.
This persistence is deliberately simple.
Warning counts survive normal restarts as long as the local persistence file remains available.
Shaw includes a small set of slash commands for managing the warning system.
| Command | Purpose |
|---|---|
/top-spoilers |
Shows the users with the highest recorded warning counts |
/spoiler-check |
Checks one user's current warning count |
/clear-user |
Lets authorized staff reset or override a user's warning count |
/clear-user is restricted to configured staff roles.
Before changing a user's count, Shaw asks the staff member to confirm the operation. Confirmed changes are then recorded in the moderation log.
Shaw was built for one Discord server, so its configuration is intentionally straightforward.
Most server-specific settings currently live near the top of main.py.
| Setting | Purpose |
|---|---|
ALLOWED_CHANNEL_IDS |
Channels where spoiler checking is active |
ALLOWED_STAFF |
Roles allowed to use restricted staff commands |
WHITELIST_ROLE_IDS |
Roles ignored by automatic spoiler checking |
LOG_CHANNEL_ID |
Destination for warning and moderation logs |
WARN_THRESHOLD |
Warning count that triggers an additional staff alert |
AUTO_DELETE_BOT_REPLY_SECONDS |
How long temporary warning messages remain visible |
PERSISTENCE_FILE |
Local JSON file used for warning counts |
The configured spoiler vocabulary is also stored directly in the project.
That makes the bot easy to understand and configure for its original purpose without adding a separate administration system.
Shaw is intentionally compact.
The current implementation primarily lives in one Python module and combines:
Discord events
│
├── spoiler matching
├── moderation actions
├── warning tracking
├── staff commands
└── persistence
Inside that module, the matching process still separates the important conceptual steps:
Find protected spans
│
▼
Find configured terms
│
▼
Compare match positions
│
▼
Decide whether the match counts
The relevant matching logic identifies three kinds of protected regions:
Discord spoilers
URLs
Markdown link text
Candidate spoiler matches are then checked against those ranges before Shaw decides whether the message should be treated as an exposed spoiler.
For the original scope of the project, keeping everything compact made deployment and configuration simple.
Finding a word in a message is easy.
The more interesting behaviour comes from all of the situations where finding the word should not produce a moderation action.
Consider a filter configured to detect a spoiler term such as Lace.
All of these strings contain the same word:
Lace
||Lace||
https://example.com/Lace
[Lace](https://example.com/)
But they do not mean the same thing to the moderation system.
In the first case, the spoiler is exposed.
In the second, the user has hidden it correctly.
In the third, it exists as part of a URL.
In the fourth, it appears inside Markdown link text that Shaw treats as protected.
So Shaw's main decision is not simply:
term found?
It is closer to:
term found?
│
▼
where was it found?
│
├── protected context → allow
│
└── exposed context → moderate
That distinction became the central technical idea of the project.
Shaw requires Python 3.10 or newer.
Clone the repository and install the dependencies:
pip install -r requirements.txtSet the Discord bot token:
export BOT_TOKEN="your bot token here"On Windows PowerShell:
$env:BOT_TOKEN="your bot token here"Then run:
python main.pyThe Discord application needs Message Content Intent enabled.
It also needs enough server permissions to:
- read messages in monitored channels;
- delete offending messages;
- send temporary warnings;
- register and use slash commands;
- and write moderation logs.
Shaw is a small server-specific project, not a general-purpose moderation framework.
Its current design reflects that scope.
Channel IDs, staff roles, log destinations, and related settings are configured directly in the application.
The configured spoiler terms are currently stored directly in main.py.
There is no external management interface for modifying the list.
Warning counts use a local JSON file instead of a database.
This is sufficient for the original environment, but the counts depend on that local file remaining available.
Matching, Discord events, staff commands, configuration, and persistence currently live in the same Python module.
That keeps the project small, but it would not be the structure I would choose for a much larger moderation system.
These limitations are part of what Shaw is:
a focused spoiler bot built for one community, not a universal text-filtering platform.
Shaw is a repost of a project originally developed on my previous GitHub account.
It is much smaller than projects such as Avenue Guard or Nauta, but I kept it public because I like the problem it ended up solving.
It began as:
Delete messages containing spoiler words.
But most of the interesting work ended up being:
Decide whether a match is actually an exposed spoiler.
That difference is why I still think the project is worth showing.
Shaw started with a rule that sounded almost trivial:
If a message contains a spoiler word, remove it.
The first counterexamples showed that the rule itself was underspecified.
If Lace is configured as a spoiler term, all of these contain the same string:
Lace
||Lace||
https://example.com/Lace
[Lace](https://example.com/)
But only the first should be treated as an exposed spoiler.
That changed the problem from word matching into interpreting where a match occurs.
Shaw first identifies spans of the message that have special meaning:
- Discord spoiler spans;
- URLs;
- Markdown-link text.
It then searches for candidate spoiler terms and checks the position of each match against those protected spans.
find candidate match
│
▼
where is it in the message?
│
├── protected span → ignore
│
└── exposed text → moderate
The regular expression is therefore only the first step.
A match is not automatically a moderation decision.
That distinction also changed how I thought about correctness. For Shaw, deleting an exposed spoiler is correct behaviour, but deleting a correctly hidden spoiler is also a bug.
So the useful questions became:
Did Shaw catch what it should catch?
and, equally:
Did Shaw leave alone what it should leave alone?
For a small project, that was the most interesting part: a seemingly simple rule became much clearer once I started looking for counterexamples instead of only testing the obvious case.
Shaw was originally written for a Silksong Discord community and later reposted from my previous GitHub account.
It remains intentionally small and server-specific.
The project is public mainly because the false-positive problem became a good example of how even a simple moderation rule can require more careful handling once it meets real user input.
Shaw is available under the MIT License.
See LICENSE for details.