A simple Reddit bot built using Python and the PRAW (Python Reddit API Wrapper) library. This bot monitors the pythonforengineers
subreddit for posts containing the phrase "i love python" and replies with a predefined message. It also keeps track of posts it has already replied to, ensuring no duplicate responses.
- Automated Replies: Replies to posts containing the phrase "i love python" with a predefined message.
- Duplicate Prevention: Tracks replied posts to avoid duplicate responses.
- Subreddit Monitoring: Monitors the
pythonforengineers
subreddit for new posts. - Logging: Prints detailed information about the posts it replies to.
To run the Reddit bot, follow these steps:
-
Install Python:
- Ensure Python 3.x is installed on your system. Download it from https://www.python.org/downloads/.
-
Install PRAW:
- Install the PRAW library using pip:
pip install praw
- Install the PRAW library using pip:
-
Clone the repository:
git clone https://github.com/M1keEm/RedditBot.git
-
Navigate to the project directory:
cd RedditBot
-
Set up Reddit API credentials:
- Create a Reddit app at https://www.reddit.com/prefs/apps.
- Add your credentials to a
praw.ini
file or directly in the script.
-
Run the bot:
python main.py
-
Monitor output:
- The bot will print details about the posts it replies to, including the title, URL, and author information.
-
Check replied posts:
- The bot maintains a list of replied posts in
posts_replied_to.txt
.
- The bot maintains a list of replied posts in
Key Components
-
PRAW Initialization:
-
The bot uses the PRAW library to interact with the Reddit API.
-
It logs in using the credentials provided in
praw.ini
.
-
-
Post Monitoring:
- The bot fetches the top 5 hot posts from the pythonforengineers subreddit.
-
Keyword Matching:
- It checks if the post title contains the phrase "i love python" (case-insensitive).
-
Reply and Logging:
-
If a match is found, the bot replies with "Manual bot test" and logs the post details.
-
The post ID is saved to
posts_replied_to.txt
to prevent duplicate replies.
-
praw.ini
File
Create a praw.ini file with the following content:
[bot1]
client_id=YOUR_CLIENT_ID
client_secret=YOUR_CLIENT_SECRET
username=YOUR_REDDIT_USERNAME
password=YOUR_REDDIT_PASSWORD
user_agent=YOUR_USER_AGENT
Replace the placeholders with your Reddit app credentials.
Customizing the Bot
-
Change the reply message: Modify the submission.reply("Manual bot test") line in
main.py
. -
Change the subreddit: Update subreddit = reddit.subreddit('pythonforengineers') to your desired subreddit.
-
Change the keyword: Update the re.search("i love python", submission.title, re.IGNORECASE) line to match a different keyword.
Contributions are welcome! If you'd like to contribute to this project, please follow these steps:
- Fork the repository.
- Create a new branch (
git checkout -b feature/YourFeatureName
). - Commit your changes (
git commit -m 'Add some feature'
). - Push to the branch (
git push origin feature/YourFeatureName
). - Open a pull request.
Please ensure your code follows the existing style and includes appropriate documentation.
This project is licensed under the MIT License. See the LICENSE file for details.
If you have any questions or suggestions, feel free to reach out:
- MikeEm - My Github
- Project Link - Repository