ea3eb899e7a024123c04b33fee410eb8893ff19b
Reddit TestPostsBot
A Reddit bot that makes test posts to your subreddit when triggered via private messages by moderators.
How It Works
- The bot runs continuously and listens for private messages sent to its account
- When a moderator sends a message containing a trigger keyword, the bot checks the wiki config
- If the trigger is found and valid, the bot posts the configured posts to the subreddit
- The bot replies to the moderator confirming success or failure
Setup
Environment Variables
Set these variables via environment or directly in bot.py:
REDDIT_CLIENT_ID: Your Reddit app's client IDREDDIT_CLIENT_SECRET: Your Reddit app's client secretREDDIT_USERNAME: The bot account's usernameREDDIT_PASSWORD: The bot account's passwordREDDIT_USER_AGENT: (Optional) Custom user agent stringSUBREDDIT: The subreddit to post to (without the /r/)WIKI_PAGE: (Optional) Wiki page for config (default:testpostsbot_config)
Wiki Configuration
Create a wiki page in your subreddit named testpostsbot_config (or set WIKI_PAGE env var) with YAML formatted triggers and posts:
posts:
- trigger: "summer-schedule"
posts:
- title: "Summer Announcement Post"
body: "This is the summer announcement."
- title: "Summer Rules Update"
body: "New summer rules are now in effect."
- trigger: "test"
posts:
- title: "Test Post"
body: "This is a test post."
- trigger: "weekly-thread"
posts:
- title: "Weekly Discussion Thread"
body: |
This is the weekly discussion thread.
Feel free to discuss anything related to the subreddit.
Each trigger can have one or multiple posts. Posts are made in order with a 2-second delay between each to avoid rate limiting.
Triggering Posts
To trigger posts, send a private message to the bot account containing the trigger keyword. For example:
- Message: "Can you run summer-schedule?" → Posts the summer schedule posts
- Message: "Trigger: test" → Posts the test post
- Message: "Please post weekly-thread" → Posts the weekly discussion thread
Only moderators of the subreddit can trigger posts.
Running the Bot
Docker
docker build -t testpostsbot .
docker run \
--env REDDIT_CLIENT_ID=your_client_id \
--env REDDIT_CLIENT_SECRET=your_client_secret \
--env REDDIT_USERNAME=bot_username \
--env REDDIT_PASSWORD=bot_password \
--env SUBREDDIT=your_subreddit \
testpostsbot
Docker Compose
# Edit docker-compose.yml with your credentials
docker-compose up
Standalone
pip install -r requirements.txt
python bot.py
Configuration Notes
- The wiki config is validated on startup. If the YAML is malformed, the bot will not start.
- The config is fetched fresh for each trigger, so you can update the wiki while the bot is running.
- Only the first matching trigger per message is processed.
- All processed messages are tracked in
DB/chat_wiki_requests.txtto avoid duplicate processing.
Description