The bot for my Discord server.
Join the Discord Server
Note: This repository does not include sensitive tokens and secrets. To use or contribute to this project, you'll need to set up your own credentials.
It's recommended to use a virtual environment to manage dependencies. For detailed instructions, refer to the official Python venv documentation.
-
Create Virtual Environment:
py -3.11 -m venv .venv
-
Activate Virtual Environment:
-
Windows:
.venv\Scripts\activate
-
pip install -r requirements.txtEnvironment variables need to be set locally using a .env file. Heroku configurations are handled separately in the Owner Setup section.
Create a .env file in the root directory of your project and add the following:
CLIENT_ID=your_discord_client_id
CLIENT_SECRET=your_discord_client_secret
TOKEN=your_discord_bot_tokenAdd your API keys to the .env file:
REPLICATE_API_TOKEN=your_replicate_api_token
OPENAI_API_KEY=your_openai_api_key-
Local Setup (
.env):If your project requires a path to a credentials JSON file, add the following to your
.envfile:GSPREADER_GOOGLE_CREDS_PATH=path/to/your/gspreader_credentials.json
Ensure that the JSON file is not committed to version control.
-
Local Setup (
.env):Add the path to your Firestore credentials JSON file:
GOOGLE_CREDENTIALS_PATH=path/to/your/google_credentials.json
Execute the following command in the root directory:
python main.pyThe bot includes a rate limiting system for ElevenLabs voice responses to prevent overconsumption of the monthly voice credit allocation:
- User Daily Limit: Each user is limited to 10 voice responses per day in the RC-talk channel
- Message Length Limit: Voice responses are capped at 200 characters to conserve credits
- Model Optimization: Using GPT-4o-mini for cost efficiency
These limits can be adjusted in the openai_bot.py file by modifying the following constants:
# Maximum daily voice interactions per user
MAX_DAILY_VOICE_USES = 10
# Maximum message length for voice generation to save credits
MAX_VOICE_MESSAGE_LENGTH = 200To debug the bot using VSCode:
- Open
main.pyin VSCode. - Press the Run button or use the shortcut
F5to start the debugger.
Unit tests are located in the tests/unit_tests directory.
-
Set Up Environment Variables for Testing:
Ensure that
PYTHONPATHis set to the root directory. This allowspytestto locate your modules correctly.-
Windows:
set PYTHONPATH=%cd% -
macOS/Linux:
export PYTHONPATH=.
-
-
Run Unit Tests:
pytest tests/unit_tests
If you do not have
pytestinstalled, you can install it using:pip install pytest
For more information, refer to the pytest documentation.
Contributions are welcome! Here's how you can help:
-
Areas of Interest:
bot/on_messagefolderbot/scriptsfolder
-
Steps to Contribute:
- Fork the repository.
- Create a new branch for your feature or bugfix.
- Commit your changes with clear messages.
- Push to your fork and submit a Pull Request.
Please ensure that you adhere to the project's coding standards and include tests for your contributions.
This section is intended for the project owner only.
Environment variables need to be set on Heroku to ensure the bot functions correctly in the production environment.
-
Navigate to Heroku Dashboard:
- Go to your Heroku Dashboard and select your app.
-
Set Config Vars:
-
Navigate to the Settings tab.
-
Click on "Reveal Config Vars".
-
Add the following variables:
CLIENT_ID=your_discord_client_id CLIENT_SECRET=your_discord_client_secret TOKEN=your_discord_bot_tokenREPLICATE_API_TOKEN=your_replicate_api_token OPENAI_API_KEY=your_openai_api_key-
gspreader [Service Account]:
GSPREADER_GOOGLE_CREDS={"your": "json_content"} -
Firestore and Google Drive [Service Account]:
GOOGLE_CREDENTIALS={"your": "json_content"}
Ensure that the JSON content is properly formatted as a single-line string.
-
-
This project is configured to automatically deploy to Heroku when you push to the main branch.
-
Ensure Heroku Remote is Set:
git remote add heroku https://git.heroku.com/cuomoputer.git
-
Push to Heroku:
heroku login git push heroku main
-
Create a Discord Application:
- Go to the Discord Developer Portal.
- Click on "New Application" and follow the prompts to create your bot.
-
Authorize the Bot:
-
Use the following URL template to authorize your bot:
https://discord.com/oauth2/authorize?client_id=YOUR_BOT_CLIENT_ID&scope=bot&permissions=PERMISSIONS_INT -
Replace
YOUR_BOT_CLIENT_IDwith your bot's client ID. -
Set
PERMISSIONS_INTto the desired permissions integer (e.g.,8for admin).
-
Ensure that sensitive information such as CLIENT_ID, CLIENT_SECRET, and TOKEN are securely stored and never committed to version control.
Happy Coding! 🚀