This project is a Reddit automation bot designed to perform various tasks on Reddit, such as logging into an account, posting images with titles, and commenting on specific posts. The bot uses Selenium integrated with Undetected ChromeDriver to automate browser interactions, ensuring stability and stealth.
- Automatically logs into a Reddit account using the credentials securely stored in a
.envfile. - Ensures a smooth and error-free login process.
- Uploads images with descriptive titles to a specified subreddit.
- Retrieves titles dynamically from a JSON file (
image_titles.json).
- Posts random comments to a target post using predefined text stored in a
comments.txtfile. - Ensures randomized interaction to avoid detection.
- Environment variables are used for customizable settings, enabling flexibility in bot behavior without modifying code.
Before setting up the bot, ensure you meet the following requirements:
- Install Python 3.7 or above.
- Ensure the latest version of Google Chrome is installed on your system.
- Chrome updates may require an updated ChromeDriver, so keep both in sync.
Install the following dependencies:
seleniumundetected-chromedriverpython-dotenv
Open your terminal and run the following commands:
# Clone the repository
git clone https://github.com/Kirtan-Rajesh/Reddit_Bot.git
# Navigate into the project directory
cd Reddit_BotCreating a virtual environment helps manage dependencies without affecting your global Python installation.
-
Create a virtual environment:
python -m venv venv
-
Activate the virtual environment:
- On macOS/Linux:
source venv/bin/activate - On Windows:
venv\Scripts\activate
- On macOS/Linux:
Install all required Python packages using the requirements.txt file:
pip install -r requirements.txtCreate a .env file in the root directory of the project with the following content:
REDDIT_USERNAME=<your_reddit_username>
REDDIT_PASSWORD=<your_reddit_password>
IMAGE_FOLDER=<path_to_folder_with_images>
COMMENTS_FILE=<path_to_comments.txt>
TITLES_FILE=<path_to_image_titles.json>
TARGET_POST_URL=<url_of_the_target_post>
Replace the placeholder values (e.g., <your_reddit_username>) with actual data for your Reddit account and file paths.
-
Images:
- Place all images you want to upload in the folder specified in
IMAGE_FOLDER.
- Place all images you want to upload in the folder specified in
-
Comments:
- Create a
comments.txtfile containing comments, one per line, for randomized posting. Example:This is an amazing post! Loved the content, keep it up! Incredible insights, thank you for sharing!
- Create a
-
Titles:
- Create an
image_titles.jsonfile to map image filenames to their respective titles. Example:{ "image1.jpg": "A Funny Meme Title", "image2.png": "Another Interesting Meme Title", "image3.jpeg": "Insightful Meme Title" }
- Create an
To execute the bot, simply run the following command:
python reddit_bot.pyThe bot performs the following steps:
- Logs into Reddit using the credentials specified in the
.envfile. - Posts a random image from the specified folder along with its title.
- Posts a random comment to the specified target post.
- Initially attempted to use Appium for mobile browser automation, but faced compatibility issues with ChromeDriver.
- Switched to Selenium with Undetected ChromeDriver for better stability and ease of use.
- Encountered difficulties in locating dynamic elements (e.g., comment boxes, post buttons).
- Resolved these issues by using
WebDriverWaitand explicit conditions in Selenium.
- Regular Chrome updates required ensuring that the ChromeDriver version matched the browser version.
- Addressed this by keeping Chrome and ChromeDriver in sync.
- Managed Reddit's API rate limits by pacing automation tasks to avoid triggering security measures.
-
Additional Features:
- Implement functionalities like upvoting posts or replying to comments.
- Enable multiple account support for diverse interactions.
-
Improved Error Handling:
- Add robust exception handling for scenarios where dynamic elements are missing or change frequently.
-
AI Integration:
- Use AI models to generate more engaging comments and post titles dynamically.
-
Scheduling Support:
- Add features to schedule posts and comments for specific times.
We welcome contributions! If you'd like to contribute:
- Fork the repository and create a new branch.
- Make your changes or additions.
- Submit a pull request with a clear description of your modifications.
For any queries or suggestions, feel free to open an issue in the repository.
For questions, you can reach out via:
- GitHub Issues: GitHub Repository
- Email: [email protected]
This bot demonstrates expertise in browser automation, showcasing how tools like Selenium can be used to interact with websites dynamically and efficiently.