β οΈ Project may have bugs and functionality limitations are there. Work has been started in favour of a better project using agent. (will share further details soon)
I have worked hard to fix the ones I found but still feel free to raise any issues. All contributions are welcome.
This project is a Reddit userbot built using the Python Reddit API Wrapper (PRAW). The bot is designed to interact with Reddit by upvoting and replying to comments in a specific subreddit. It demonstrates basic usage of the PRAW library and serves as a starting point for building more advanced Reddit bots.
- Changelog
- Features
- Prerequisites
- Installation
- Usage
- Notes
- Notices
- Example Output
- Troubleshooting
- Contribution Guidelines
- Enhanced userbot functionality with improved logging, error handling, and colored terminal output.
- Integrated Google GenAI (Gemini) for generating intelligent replies to comments.
- Added configurable options for upvoting, replying, and clearing votes.
- Introduced
output.pyfor color formatting and cycling. - Updated dependencies and added comprehensive API usage notes.
- Improved documentation with detailed setup instructions and troubleshooting.
- Basic Reddit userbot using PRAW for upvoting and replying to comments.
- Simple configuration via
.inifile. - Basic error handling and logging.
- π Automatically upvotes and replies to comments in a specified subreddit.
- βοΈ Configurable through an
.inifile. - π Uses PRAW for seamless interaction with Reddit's API.
- π οΈ Improved logging and error handling for better debugging.
- π¨ Colored output in the terminal for enhanced visibility.
- π Enhanced userbot functionality with options for upvoting, replying, and clearing votes.
- π€ Integrated Google GenAI (Gemini) for generating intelligent replies.
- π» (Upcoming) local model support via REST API
- π₯οΈ (Upcoming) local model support via OpenAI API
- π
output.pyfile for handling output colour formatting and color cycling (looked fun in hindsight)
- Python 3.12.6 (NOT tested for other versions)
- A Reddit account
- Reddit API credentials (client ID, client secret, username, password, and user agent)
- Google account to obtain API key (from Google AI Studio) for replies
- Required Python packages (see
requirements.txtfor full list):praw==7.8.1google-genai==1.44.0
-
Clone this repository:
git clone https://github.com/ParthProLegend/reddit-userbot-praw-basic.git cd reddit-userbot-praw-basic -
Install the required dependencies:
pip install -r requirements.txt
Note: It is recommended to use a virtual environment to avoid conflicts with system packages. Create and activate one with:
python -m venv venv # On Windows: venv\Scripts\activate # On Linux/Mac: source venv/bin/activate
-
Create a
.inifile in the root directory and add your Reddit API credentials:[account_reddit] client_id = YOUR_CLIENT_ID client_secret = YOUR_CLIENT_SECRET username = YOUR_USERNAME password = YOUR_PASSWORD user_agent = YOUR_USER_AGENT subreddit = YOUR_SUBREDDIT number_of_submissions_to_check = NUMBER (default:20 if not provided)
Note: The
.inifile contains sensitive information (API keys, credentials) and is not tracked by Git (see.gitignore). Do not commit it to version control to avoid exposing your credentials.Note: For Setting Up the PRAW interface to obtain client_id and client_secret, check out OAuth2 Quick Start:First Steps
-
(optional) Generate your own API key from Google AI Studio and here's the Guide to generate API key on Google AI Studio
-
Additional configuration in the
.inifile is required for logging and Google GenAI integration.[logging] level = INFO file = app.log [google_api] google-genai = 1.44.0 GEMINI_API_KEY = YOUR_API_KEY system_instruction = YOUR_SYSTEM_INTRUCTIONS (like:"Always be friendly and polite.", etc.) response_base = RESPONSE_BASE {having 3 entries as "{comment_body}", "{submission_title}" and "{submission_selftext}"} (like: 'Respond to \"{comment_body}\" which was a response to \"Title: {submission_title} and Content: {submission_selftext}\"'.)
-
Run the bot:
python main.py
-
The bot will upvote and reply to comments in the specified subreddit.
-
(Pending Implementation) Configure the bot's behavior in the
.inifile:[bot_settings] upvote_comments = True reply_to_comments = True clear_votes = True
-
To use Google GenAI (Gemini) for replies, set up the
GOOGLE_API_KEYin the.inifile.
- The bot clears upvotes after a short delay to comply with Reddit's rules.
- Ensure that your bot's actions comply with Reddit's API terms of service.
- For detailed output logs, check the
app.logfile or whatever is defined in your .ini. - The logging configuration can be adjusted in the
main.pyand.inifile. By default, it logs toapp.logwith a log level ofINFO. - The
ColorCyclerclass is used for cycling colors in terminal output. Ensure your terminal supports ANSI colors.
The bot need .ini file to run successfully, like this sample (with auto-replying enabled):
For Setting Up the PRAW interface to obtain client_id and client_secret, check out OAuth2 Quick Start:First Steps
[account_reddit]
client_id = YOUR_CLIENT_ID
client_secret = YOUR_CLIENT_SECRET
password = YOUR_ACCOUNT_PASSWORD
user_agent = PythonDesktop:PRAW:0.0.2 (by /u/RedditUsername for Testing Purposes)
username = YOUR_ACCOUNT_USERNAME
subreddit = SUBREDDIT_NAME_WHERE_YOU_WANT_TO_RUN_THE_BOT
number_of_submissions_to_check = NUMBER_OF_SUBMISSIONS_TO_CHECK_IN_THE_SUB_USING_NEW_SORTING
[google_api]
google-genai = 1.44.0
GEMINI_API_KEY = YOUR_GEMINI_API_KEY
system_instruction = YOUR_SYSTEM_INSTRUCTION (like: You are a human. Always be family friendly and polite, do not lie, do not respond professionally like a bot. You are not OP, and you does not refer to you.)
response_base = YOUR_RESPONSE_BASE (like: Give a short response to "{comment_body}" in response to a reddit with \"Title: {submission_title} and Content: {submission_selftext}\" in about 20 words.)
[logging]
enabled = True ; (Not Implemented Yet, planned)
level = INFO (Choose between DEBUG/INFO)
file = app.log (or any FILE_NAME.log)
[configuration]
USER_AGENT = "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/91.0.4472.124 Safari/537.36"
PROXY = None
REQUEST_DELAY = 15
MAX_RETRIES = 10
ERROR_TIMEOUT = 60This project uses the PRAW library to interact with Reddit's API. PRAW is developed and maintained by the PRAW Dev Team. For more information, visit the PRAW GitHub repository.
- This bot interacts with Reddit's API and complies with Reddit's API Terms of Service.
- Ensure that the bot's actions do not violate Reddit's rules resulting in your account suspension.
- Important Notes:
- Reddit API access requires a properly configured app. Follow the OAuth setup guide linked in Installation.
- Be aware of Reddit's rate limits; excessive requests may lead to temporary bans. The bot includes built-in delays to mitigate this.
- This bot interacts with Google's API and complies with Google's Gemini API Terms of Service.
- For more information, visit the Google Gemini API documentation.
- Important Notes:
- Google Gemini API usage may incur costs beyond the free tier limits. Check Google's pricing for details.
- Keep your
GEMINI_API_KEYsecure and do not share it publicly to avoid unauthorized usage and potential charges. - The bot uses the "gemini-2.5-flash" model; ensure your API key has access to this model or adjust in the code if needed.
- This project is licensed under the GNU Affero General Public License v3.0. See the LICENSE file for details.
- PRAW is licensed under the BSD 2-Clause License. See the PRAW License for details.
- Google GenAI (Gemini) is integrated into this project for enhanced reply generation. For more information, visit the Google Gemini API documentation.
- Google and Gemini are trademarks of Google LLC. This project is not affiliated with Google, LLC or any of their partners.
- Reddit and the Reddit logo are registered trademarks of Reddit, Inc. This project is not affiliated with Reddit, Inc or any of their partners.
PRAW, an acronym for "Python Reddit API Wrapper", is a Python package that allows for simple access to Reddit's API. PRAW aims to be easy to use and internally follows all of Reddit's API rules. With PRAW there's no need to introduce sleep calls in your code. Give your client an appropriate user agent and you're set.
- This project is provided "as is" without any warranties or guarantees. Use it at your own risk.
- The author is not liable for any damages or issues arising from the use of this project.
- It is your responsibility to ensure that your use of this project complies with Reddit's API terms and any other applicable laws.
When the bot runs at INFO level logging successfully, you might see colored output like this (colors depend on your terminal support):
ID: abc123 Title: Example Title Score: 42
URL: https://www.reddit.com/r/example/comments/abc123
Post: This is the post content.
https://www.reddit.com/r/example/comments/abc123/comment/xyz456
Comment: This is a comment.
β
Userbot upvoted and cleared vote successfully.
β
Userbot replied successfully.
π€π― Check out my GitHub at https://github.com/ParthProLegend
π€π― and this project is located at https://github.com/ParthProLegend/reddit-userbot-praw-basic
Remember to star the repository if you find it useful! π
Buy me a coffee at https://ko-fi.com/parthprolegend to support my work. βοΈ- Issue:
Invalid credentialserror.- Solution: Double-check your
.inifile for correct Reddit API credentials.
- Solution: Double-check your
- Issue: Bot does not upvote or reply.
- Solution: Ensure the subreddit exists and has new posts.
- Issue: Rate limit errors.
- Solution: Reduce the bot's activity or add delays between actions.
- Issue: Google GenAI integration problems.
- Solution: Verify
GOOGLE_API_KEYin the.inifile and check your Google Cloud project settings.
- Solution: Verify
- Issue: Colored terminal output not working.
- Solution: Ensure your terminal supports ANSI colors. If using Windows, consider using Windows Terminal or enabling ANSI support in the command prompt.
Contributions are welcome! To contribute:
- Fork the repository.
- Create a new branch for your feature or bug fix.
- Commit your changes and push them to your fork.
- Submit a pull request with a detailed description of your changes.
For bug reports or feature requests, please open an issue on the GitHub repository.