https://github.com/amberlee2427/brian-bot
A Discord bot for D&D servers with OpenAI integration, character sheet management, dice rolling, and more. Built with Python and designed for security and ease of use.
Science Score: 26.0%
This score indicates how likely this project is to be science-related based on various indicators:
-
○CITATION.cff file
-
✓codemeta.json file
Found codemeta.json file -
✓.zenodo.json file
Found .zenodo.json file -
○DOI references
-
○Academic publication links
-
○Committers with academic emails
-
○Institutional organization owner
-
○JOSS paper metadata
-
○Scientific vocabulary similarity
Low similarity (14.8%) to scientific vocabulary
Keywords
Repository
A Discord bot for D&D servers with OpenAI integration, character sheet management, dice rolling, and more. Built with Python and designed for security and ease of use.
Basic Info
Statistics
- Stars: 0
- Watchers: 0
- Forks: 0
- Open Issues: 0
- Releases: 2
Topics
Metadata Files
README.md
Brian Bot
A helpful Discord assistant built with Python and OpenAI. Brian is designed to be a secure, efficient, and friendly bot that can help manage and interact with your Discord server.

Features
- Natural Conversations: Chat with Brian using natural language
- Channel Summarization: Get quick summaries of channel discussions
- Message Search: Find specific messages across configured channels
- Security First: Built with security best practices including rate limiting and input sanitization
- Multi-bot Friendly: Properly handles conversations with other bots
Setup
Prerequisites
Create a Discord Bot:
- Go to Discord Developer Portal
- Click "New Application" and give it a name
- Add the
Brain1.pngorBrain2.pngimage as Brian's profile pic - Go to the "Installation" tab and select
Nonefor the Install link - Go to the "Bot" tab and turn of the "PUBLIC BOT" toggle
- Under "Privileged Gateway Intents", enable:
- MESSAGE CONTENT INTENT
- SERVER MEMBERS INTENT
- Copy the bot token and save it somewhere secure (you'll need this for the
.envfile) - Go to OAuth2 > URL Generator
- Select scopes:
botandapplications.commands - Select bot permissions:
- Read Messages/View Channels
- Send Messages
- Read Message History
- Add Reactions
- Use Slash Commands
- Copy the generated URL and paste in into a new tab to invite the bot to your server
Get an OpenAI API Key:
- Go to OpenAI Platform
- Sign up or log in
- Go to API Keys section
- Click "Create new secret key"
- Copy the API key (you'll need this for the
.envfile) - Note: The API key starts with "sk-" and is used for billing
- Note: You will likely need to prepay for tokens. Add a small amount of credit e.g. $5. You may be able to sell you data to OpenAI for $120 of credits a month, but not until you are on the appropriate member tier. So pay for a few calls and then consider selling your D&D anticts for effectively unlimited API usage.
- Note: Monitor this account for unexpected activity and reset your tokens if you are suspicious.
Local Development
- Fork and Clone the Repository: Fork this repository to your GitHub account by clicking the "Fork" button at the top of the page.
Clone the repo locally:
bash
git clone https://github.com/yourusername/brian-bot.git
cd brian-bot
We recommend you "Watch" the repo in order to be notified of updates
- Click the "Watch" button at the top of the repository
- Select "Custom" to configure notifications
- Enable notifications for:
- "Releases" (when new versions are published)
- "Discussions" (for community support)
- "Security alerts" (for important security updates)
- Click "Apply" to save your preferences
- Create a
.envfile: In the same directory, create a file named.envand add your secret keys: ``` # Required DISCORDTOKEN=yourdiscordbottokengoeshere OPENAIAPIKEY=youropenaiapikeygoes_here
# Optional (with defaults) SESSIONNOTESCHANNEL=your-session-notes-channel-name # Default: session-notes DATADIR=characters # Default: characters COMMANDPREFIX=! # Default: ! MODELNAME=gpt-4 # Default: gpt-4 MAXTOKENSFORRESPONSE=1500 # Default: 1500 RATELIMITMENTIONS=5 # Default: 5 mentions per minute RATELIMITCOMMANDS=10 # Default: 10 commands per minute RATELIMITWINDOW=60 # Default: 60 seconds
# Channel and Role Configuration SEARCHABLECHANNELIDS=123456789012345678,876543210987654321 # Comma-separated list of channel IDs for !find command ALLOWEDROLES=123456789012345678,876543210987654321 # Comma-separated list of role IDs that can use restricted commands ADMINROLES=123456789012345678,876543210987654321 # Comma-separated list of role IDs with admin privileges ```
After creating the .env file, secure it with:
bash
chmod 600 .env
This ensures only your user can read and write to the file.
Install Dependencies:
bash pip install -r requirements.txtRun the Bot:
bash python main.py
Railway Deployment
Create Required Accounts:
- Sign up for a GitHub account if you don't have one
- Sign up at Railway.app
- Install the Railway CLI (optional)
Fork and Clone:
- Fork this repository to your GitHub account by clicking the "Fork" button at the top of the page
- We recommend you "Watch" the repo in order to be notified of updates
- Click the "Watch" button at the top of the repository
- Select "Custom" to configure notifications
- Enable notifications for:
- "Releases" (when new versions are published)
- "Discussions" (for community support)
- "Security alerts" (for important security updates)
- Click "Apply" to save your preferences
Deploy to Railway:
- Create a new project in Railway
- Connect your GitHub account if not already connected
- Select your forked repository
- If the repo isn't showing up under the GitHub options:
- Scroll to the bottom of the page and select "Empty Project"
- Select "Add a service" > "GitHub Repo" > "Configure GitHub App" >
- You may need to Authenticate to continue
- Under "Repository Access", select either:
- "All repositiories" or
- "Only select repositories" and choose "brain-bot" from the dropdown list
- "Save"
- Add the following environment variables in Railway:
- Where:
- In "Architecture" view in your project space, click on the
brain-botbox - Select the "Variables" tab
New Variable- Paste or type in the relevant content.
- Required:
DISCORD_TOKEN: Your Discord bot tokenOPENAI_API_KEY: Your OpenAI API key- Optional (with defaults):
SESSION_NOTES_CHANNEL: The name of your session notes channel (without the #)DATA_DIR: (Optional, recommended) Custom directory for character sheetsCOMMAND_PREFIX: Bot command prefix (default: !)MODEL_NAME: OpenAI model to use (default: gpt-4)MAX_TOKENS_FOR_RESPONSE: Maximum tokens for AI responses (default: 1500)RATE_LIMIT_MENTIONS: Mentions allowed per minute (default: 5)RATE_LIMIT_COMMANDS: Commands allowed per minute (default: 10)RATE_LIMIT_WINDOW: Rate limit window in seconds (default: 60)- Channel and Role Configuration:
SEARCHABLE_CHANNEL_IDS: Comma-separated list of channel IDs for the !find commandALLOWED_ROLES: Comma-separated list of role IDs that can use restricted commandsADMIN_ROLES: Comma-separated list of role IDs with admin privileges- Secure the Token and API Key variables by selecting the triple dot and
Seal, if the option is available.
Configure the Bot:
- The bot will automatically deploy when you push to the main branch (this could take a few minutes)
- Monitor the deployment in the Railway dashboard
- Check the logs for any issues
Updating the Bot:
- Push changes to your repository or "Sync Fork" with the main repo
- Railway will automatically redeploy
- Monitor the deployment status in the dashboard
Setting Up Persistent Storage (Optional but Recommended)
To ensure your character sheets persist across deployments and restarts, you can set up a storage service on Railway:
Add Storage Service:
- In your Railway project dashboard, click "New"
- Select "Storage" from the service options
- Choose a name for your storage service (e.g., "brian-storage")
Configure Storage:
- Once created, Railway will provide a mount path
- Add this environment variable to your bot service:
DATA_DIR=/data/characters - This will store character sheets in the persistent storage volume
Verify Setup:
- Deploy your bot
- Create a character sheet using
!coinor by mentioning Brian - Check the
/data/charactersdirectory in your storage service - Your character sheets should persist even if the bot restarts
Note: If you don't set up persistent storage, character sheets will be stored in the bot's ephemeral filesystem and will be lost when the bot restarts or redeploys.
Usage
- Chat: Mention
@Brianin a message to start a conversation - Summarize: Use
!summarize #channel-nameto get a summary of that channel - Recap: Use
!recapfor a quick summary of your session notes channel - Find: Use
!find your search queryto look for messages in configured channels
Security Features
- Rate limiting to prevent abuse
- Input sanitization for all user inputs
- Role-based access control
- API key validation
- Secure error handling
- Message length limits
Troubleshooting
Bot not responding:
- Check if the bot is online
- Verify API keys in
.envor Railway environment variables - Check bot permissions in Discord
Commands not working:
- Ensure the bot has necessary permissions
- Check if you have the required roles
- Verify channel permissions
Rate limiting:
- Wait 60 seconds before trying again
- Contact server admin if persistent
Railway Deployment Issues:
- Check Railway logs for errors
- Verify environment variables are set correctly
- Ensure the Procfile and runtime.txt are present
- Check if the build process completed successfully
Contributing
- Fork the repository
- Create a feature branch
- Commit your changes
- Push to the branch
- Create a Pull Request
Please read CONTRIBUTING.md for details on our code of conduct and the process for submitting pull requests.
Security
If you discover any security-related issues, please email [your-email] instead of using the issue tracker.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Acknowledgments
- OpenAI for the GPT API
- Discord.py for the Discord API wrapper
- All contributors who have helped improve Brian
Release Notes
Initial release of Brian Bot, a Discord bot for D&D servers with the following features:
- Natural language conversations with OpenAI integration
- Character sheet management
- Dice rolling
- Channel summarization
- Message search
- Session notes tracking
- Rate limiting and security features
Key Features: - Default character sheet template - Persistent storage support - Configurable through environment variables - Railway deployment support - Comprehensive documentation
This is the first stable release of Brian Bot. All features are fully functional and documented.
Owner
- Name: Amber
- Login: AmberLee2427
- Kind: user
- Location: New Zealand
- Repositories: 1
- Profile: https://github.com/AmberLee2427
GitHub Events
Total
- Release event: 2
- Watch event: 1
- Issue comment event: 1
- Public event: 1
- Push event: 12
- Pull request event: 2
- Create event: 2
Last Year
- Release event: 2
- Watch event: 1
- Issue comment event: 1
- Public event: 1
- Push event: 12
- Pull request event: 2
- Create event: 2
Issues and Pull Requests
Last synced: 8 months ago
All Time
- Total issues: 0
- Total pull requests: 1
- Average time to close issues: N/A
- Average time to close pull requests: about 1 hour
- Total issue authors: 0
- Total pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 1.0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Past Year
- Issues: 0
- Pull requests: 1
- Average time to close issues: N/A
- Average time to close pull requests: about 1 hour
- Issue authors: 0
- Pull request authors: 1
- Average comments per issue: 0
- Average comments per pull request: 1.0
- Merged pull requests: 0
- Bot issues: 0
- Bot pull requests: 0
Top Authors
Issue Authors
Pull Request Authors
- AmberLee2427 (2)
Top Labels
Issue Labels
Pull Request Labels
Dependencies
- discord.py >=2.3.2
- httpx ==0.25.2
- openai >=1.3.0
- python-dotenv >=1.0.0
- tiktoken >=0.5.1