- Go to the Discord Developer Portal.
- Navigate to your application and select the "OAuth2" tab.
- Under "Scopes", select the
botcheckbox. - Under "Bot Permissions", select the following permissions:
- View Channels
- Send Messages
- Send Messages in Threads
- Embed Links
- Read Message History
- Use Slash Commands
- (Optional, for advanced features: Manage Messages, Embed Links, Attach Files, etc.)
- In the "Bot" section of the Developer Portal, under "Privileged Gateway Intents", enable the Message Content Intent. This is required for the bot to respond to commands in servers.
- Click Reset Token if necessary and note the token somewhere for now.
- Copy the generated OAuth2 URL and use it to invite the bot to your server.
/ai-dungeon-master/
├── README.MD
├── pyproject.toml
├── packages/
│ ├── bot/ # Discord bot (Gateway)
│ │ ├── main.py
│ │ └── cogs/
│ ├── backend/ # FastAPI backend service (AI Brain)
│ │ ├── main.py
│ │ ├── api/
│ │ ├── components/
│ └── shared/ # Shared Pydantic models
- Create a
.envfile inpackages/bot/with:ReplaceDISCORD_BOT_TOKEN=your_bot_token_hereDISCORD_BOT_TOKENwith your bot's token.
The recommended way to run the project is with Docker Compose. This will start both the backend API and the Discord bot with a single command.
-
Install Docker and Docker Compose.
-
Clone the repository and navigate to the project root:
git clone https://github.com/your-org/ai-dungeon-master.git cd ai-dungeon-master -
Build and run the stack:
# May need sudo rights docker compose up --build- The backend API will be available at http://localhost:8000.
- The Discord bot will start and connect to Discord using the provided token.
-
Test the Bot:
- Use the
/pingcommand in any channel where the bot is present to test its functionality.
- Use the
You can also find the process to manually run services here
/help: Lists all available commands and references advanced help./getting-started: Step-by-step onboarding guide for new users and server owners./cost: API usage cost info and transparency, with a link to full documentation./server-setup: Explains the shared API key model and how to submit a key. Only users with "Administrator" or "Manage Server" permissions can run this command./server-setkey [API_KEY]: Allows an admin to submit the server's shared API key. Only users with "Administrator" or "Manage Server" permissions can run this command. The key is securely sent to the backend and never shown to other users./ping: Check if the bot is alive.
All commands return ephemeral messages by default to avoid channel clutter. For advanced help, see Command Reference.
- The bot does not store API keys locally. When
/server-setkeyis used, the bot makes a secure API call to the backend service, which handles encryption and storage. - All key submission and confirmation messages are sent as ephemeral responses, ensuring only the submitting admin can view them.
- Only users with the required permissions can submit or update the server API key.
- All secrets are managed via environment variables and never hardcoded.
- The backend service uses a database to store server API keys and configuration.
- Data is stored in a structured format, following the defined database schema located in
packages/backend/database_schema_extension.sql. - The backend exposes RESTful endpoints (see
docs/architecture/api-specification.md) for the bot and other clients to interact with server settings. - For more details on the database schema and how to interact with it, refer to the
database_schema_extension.sqlfile.
- API keys are encrypted at rest by the backend using Fernet symmetric encryption.
- Keys are never exposed in logs or non-ephemeral messages.
- All secrets are managed via environment variables.
- All code is organized as a modular monolith, with clear separation between bot, backend, and shared models.
- Unit and integration tests are located in
packages/bot/tests/andpackages/backend/tests/. - Run all tests with:
pytest --maxfail=1 --disable-warnings -v
Note:
If the bot does not respond to commands in servers, ensure that the "Message Content Intent" is enabled in the Discord Developer Portal for your bot, and that the bot has the required permissions in your server.
If you prefer to run the services manually (not recommended for most users):
- From the root folder install the prerequisites using
requirements.txtpip install -r requirements.txt
-
The backend is a FastAPI app. Start it with:
uvicorn packages.backend.main:app --reload
By default, it runs on
http://localhost:8000. -
If you do not have uvicorn installed, install it with:
pip install uvicorn[standard]
- In a separate terminal, run:
python packages/bot/main.py
- Use the
/pingcommand in any channel where the bot is present to test its functionality.
- Every campaign has a persistent transcript log saved at
data/saves/[campaign_id]/transcript.log. - All in-character player messages and AI responses are recorded in this file.
- Log files are automatically rotated when they exceed 10 MB, with up to 3 rotated logs retained.
- For details on log file format and rotation policy, see
docs/architecture/observability.md.
- Logging is implemented via an async, thread-safe utility:
packages/shared/transcript_logger.py. - All log entries are structured as JSONL with
timestamp,author, andmessagefields. - Campaign IDs are validated for filesystem safety; invalid IDs are rejected and not logged.
- The logging system is fully covered by unit and integration tests (see
packages/backend/tests/test_transcript_logger.pyandpackages/backend/tests/test_message_processor.py). - For the full development story, see
docs/stories/1.6.story.md. - For log format and rotation policy, see
docs/architecture/observability.md.