Skip to main content

Crabstero

The simple nonversation Discord bot.

Crabstero is a Discord bot that learns from messages in each channel and uses Markov chains to generate responses when it is mentioned.

Overview

Crabstero is intended for Discord servers that want a lightweight chatbot with channel-local, randomly generated replies. It does not use a large language model; it learns from the channels it can read and uses that history to assemble replies when mentioned.

This repository and README are for running your own instance of Crabstero. To invite the official hosted instance instead of running your own bot, see the Crabstero project page.

Features

  • Per-channel Markov chain generation for Discord messages.
  • Automatic ingestion of accessible channel history and new messages.
  • Mention-triggered replies based on each channel's learned message history.
  • /pingme user control for opting into pings from generated mentions.
  • /forgetme user data deletion and future message ingestion opt-out.
  • SQLite-backed storage for learned message data.
  • Optional Prometheus metrics over TCP or a Unix socket.
  • systemd notification and watchdog support when run as a service.

Requirements

  • A Linux host or virtual machine.
  • Python 3.14 or newer.
  • uv for project and Python management; it can download the requested interpreter, so Python does not need to be installed system-wide.
  • A Discord application with a bot token and the Message Content intent enabled.
  • Discord channel permissions to view channels, read message history, and send messages where Crabstero should operate.

Discord setup

In the Discord Developer Portal, create an application, add a bot, and enable the Message Content intent for the bot. Crabstero reads message content and embed text to learn channel-local chains, so it cannot ingest channel history normally without that privileged intent.

Invite the application with these OAuth2 scopes:

Scope Why Crabstero uses it
bot Add the bot user to the selected server.
applications.commands Install the /pingme and /forgetme slash commands.

Recommended bot permissions:

Permission Why Crabstero uses it
View Channels See the channels it should learn from and reply in.
Send Messages Send generated replies when mentioned.
Send Messages in Threads Reply when mentioned inside threads.
Embed Links Send occasional generated embed replies.
Read Message History Ingest accessible channel history on startup.
Use External Emojis Preserve learned custom emoji tokens in generated replies.

The combined permissions integer for the recommended set is 274878254080.

Example self-hosted invite URL:

https://discord.com/oauth2/authorize?client_id=YOUR_CLIENT_ID&scope=bot%20applications.commands&permissions=274878254080

Replace YOUR_CLIENT_ID with the application ID from the Discord Developer Portal. Channel permission overwrites still apply, so you can limit where Crabstero learns and replies by restricting the bot role per channel.

Installation

Create a directory for Crabstero, create a Python 3.15 virtual environment, and install the package from PyPI:

mkdir crabstero && cd crabstero
uv venv --python 3.15
uv pip install crabstero

Usage

Run Crabstero with a Discord bot token from the environment:

TOKEN="your-discord-bot-token" uv run crabstero --database-path crabstero.db

On startup, Crabstero opens or creates the configured SQLite database, connects to Discord, and begins ingesting channel history and new messages it can read. Mention the bot in a channel to receive a generated reply once enough channel data has been collected.

Configuration

Crabstero is configured through CLI flags, environment variables, and systemd credentials. CLI flags take precedence over environment defaults where both are available.

Setting CLI flag Environment variable Fallback/default Description
Discord token --token TOKEN systemd credential token Required Discord bot token.
Database path --database-path, --database DATABASE_PATH crabstero.db SQLite database file path.
Ingest-only mode --ingest-only disabled Ingest history and real-time messages without replying.
Metrics listener --listen-metrics LISTEN_METRICS disabled Prometheus metrics address, either HOST:PORT or unix:/path.sock.
Metrics socket mode --metrics-unix-socket-mode METRICS_UNIX_SOCKET_MODE unchanged Octal file mode for Unix socket metrics listeners.

When running under systemd, Crabstero can read the bot token from a credential named token. It also sends readiness, stopping, and watchdog notifications when the relevant systemd environment variables are present.

Development

Clone the Git repository and use uv to sync the project environment from the lockfile:

git clone https://github.com/LogalDeveloper/Crabstero
cd Crabstero
uv sync --locked --python 3.15

The development toolchain uses Ruff for formatting and linting, mypy for type checking, codespell for typo detection, pip-audit for dependency auditing, and pytest with pytest-cov and Coverage.py for tests and coverage reporting.

Run the common checks:

uv run ruff format --check --diff .
uv run ruff check .
uv run mypy .
uv run codespell
uv run pip-audit --skip-editable
uv run pytest

Run tests with coverage reporting:

uv run pytest -v --cov --cov-report=
uv run coverage report

Tests are organized under tests/unit and tests/integration. The pytest configuration marks tests automatically based on those directories.

License

Crabstero is licensed under the Apache License 2.0. See LICENSE.txt for the full license text.

Metadata

Release files for crabstero 1.3.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for crabstero 1.3.1
File Size Uploaded Provenance
crabstero-1.3.1.tar.gz 153.5 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for crabstero 1.3.1
File Interpreter ABI Platform
crabstero-1.3.1-py3-none-any.whl Python 3 none any Details

Total release size: 195.5 kB

Release files / crabstero-1.3.1.tar.gz

Download URL crabstero-1.3.1.tar.gz
Size 153.5 kB
Tags Source
SHA-256 checksum
How to use checksums
69a6a610a5a5401ee39d83fe2dd24c1649f20dea833c1c12a4ac4c9f5536dc71
BLAKE2b-256 checksum
How to use checksums
3d54a76cdc885cf1b66bfe398de861f83d4106afb93ccd47205077305ab01304
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Release files / crabstero-1.3.1-py3-none-any.whl

Download URL crabstero-1.3.1-py3-none-any.whl
Size 42.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
0f5e779be4edde4869f3696b0d159bf06c32caed38af4b6e9522282db1431760
BLAKE2b-256 checksum
How to use checksums
def41fdf72c8b258aa39eeec5d56920119d901a8e0a622204e01104b2a6fc798
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.13.1 {"installer":{"name":"uv","version":"0.13.1","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

Security for crabstero 1.3.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page