Your personal Reddit trend analyst, right in your Discord server.
SubTrends is a Discord bot that turns the latest posts and comments from any subreddit into a concise, engaging trend brief using OpenAI GPT models.
- Subreddit analysis: Summarizes themes, sentiment, and hot takes across recent top posts and comments.
- OpenAI-powered summaries: Uses OpenAI Chat Completions (e.g.,
gpt-5-mini,gpt-5). - Top post links: Includes direct links to the posts referenced.
- Model selection: Change the model on the fly with a slash command.
- History & autocomplete: Personal per-user history, used to autocomplete
subredditwhen typing/trend. - Long message splitting: Automatically splits long results to fit Discord limits.
- Persistent sessions: Stores user model choices and history on disk.
- Rate-limited & resilient: Built-in rate limiting, OAuth token caching, and timeouts for Reddit/OpenAI.
- Docker support: Container build for easy deployment.
- A user invokes
/trend <subreddit>. - The bot fetches top posts and their top comments via the Reddit API (with OAuth).
- Content is summarized by OpenAI using a structured prompt.
- The bot returns a formatted brief with a header and top post links.
graph TD
A[User on Discord] -- /trend subreddit --> B(SubTrends Bot)
B -- Fetch top posts/comments --> C(Reddit API)
C -- Returns data --> B
B -- Send data for summary --> D(OpenAI API)
D -- Returns summary --> B
B -- Post summary --> A
/trend <subreddit>: Analyze a subreddit (type withoutr/). Autocomplete pulls from your history./model <model>: Change the summary model.- Available choices are provided in Discord. Current options:
gpt-5-miniβ fast and efficient (default)gpt-5β most capable
- Available choices are provided in Discord. Current options:
/history: Show your last N analyzed subreddits (configurable; default 25)./clear: Clear your history.
Legacy text command is also supported by default: type !trend <subreddit>.
- Go 1.23+
- Docker (optional)
- A Reddit app (client ID/secret)
- A Discord bot (token)
- An OpenAI API key
git clone https://github.com/your-username/subtrends.git
cd subtrendsCreate .env in the project root:
# .env
# Discord
DISCORD_BOT_TOKEN=your_discord_bot_token
# Reddit (https://www.reddit.com/prefs/apps)
REDDIT_CLIENT_ID=your_reddit_client_id
REDDIT_CLIENT_SECRET=your_reddit_client_secret
# OpenAI
OPENAI_API_KEY=your_openai_api_key
# --- Optional settings (override defaults from config.go) ---
REDDIT_POST_LIMIT=7
REDDIT_COMMENT_LIMIT=7
REDDIT_TIMEFRAME=day # day, week, month, year, allYou can also generate a starter file with make init-env.
Using Go:
go mod tidy
go run .Using Makefile helpers:
make run # run locally, respects .env if presentUsing Docker:
docker build -t subtrends .
# Mount local data/ into container for persistence across restarts
docker run --env-file .env --name subtrends-bot -d -v $(pwd)/data:/app/data subtrendsThe bot is configured via environment variables. Important settings:
DISCORD_BOT_TOKEN: Discord bot tokenREDDIT_CLIENT_ID,REDDIT_CLIENT_SECRET: Reddit OAuth credentialsOPENAI_API_KEY: OpenAI API key
OPENAI_API_ENDPOINT(defaulthttps://api.openai.com/v1/chat/completions)OPENAI_REQUEST_TIMEOUT(default45s)OPENAI_REQUESTS_PER_MINUTE(default10)OPENAI_BURST_SIZE(default3)SUMMARY_HEADER(defaultπ± *REDDIT PULSE* π±\n\n)
REDDIT_BASE_URL(defaulthttps://oauth.reddit.com)REDDIT_AUTH_URL(defaulthttps://www.reddit.com/api/v1/access_token)REDDIT_POST_LIMIT(default7)REDDIT_COMMENT_LIMIT(default7)REDDIT_TIMEFRAME(defaultday; one ofday,week,month,year,all)REDDIT_REQUESTS_PER_SECOND(default1)REDDIT_BURST_SIZE(default5)REDDIT_TOKEN_EXPIRY_BUFFER(default5m)REDDIT_TOKEN_FILE_PATH(defaultdata/reddit_token.json)REDDIT_REQUEST_TIMEOUT(default10s)REDDIT_CONCURRENT_REQUESTS(default3)REDDIT_USER_AGENT(defaultSubTrends/1.0)REDDIT_PUBLIC_URL(defaulthttps://reddit.com)
SESSION_FILE_PATH(defaultdata/sessions.json)HISTORY_INIT_CAPACITY(default50)HISTORY_DISPLAY_LIMIT(default25)DISCORD_MESSAGE_SPLIT_LENGTH(default1900)LEGACY_COMMAND_PREFIX(default!trend)SHUTDOWN_TIMEOUT(default5s)
The current model options are presented as Discord choices:
gpt-5-miniβ fast and efficient (default)gpt-5β most capable
Choose with /model. Your selection is saved per-user.
make helpβ list tasksmake runβ run locallymake buildβ build binary tobin/subtrends-botmake tidyβgo mod tidymake test/make coverageβ run tests and generate reportmake docker-build/make docker-runβ build/run container
- User sessions (history, chosen model):
data/sessions.json - Reddit OAuth token cache:
data/reddit_token.json
Both files are created automatically. They are written with file mode 0600. When using Docker, they persist if you bind mount data/.
- Go + discordgo
- OpenAI Chat Completions API
- Reddit API (OAuth)
- Docker