Avoiding repeated messages in my Reddit-to-Telegram bot

Hi there! I made a bot that grabs posts from Reddit and sends them to my Telegram channel. The bot checks for new content every couple of minutes but keeps sending the same posts over and over again. I need help figuring out how to remember which posts were already shared so my bot stops spamming the same content. What would work better - storing this info in memory or maybe using a simple database? Looking for any tips or code examples that might help me solve this problem.

redis is perfect for this if ur okay with runnin another service. use SET with expiration times on post IDs - they’ll auto-delete after a few days. much faster than readin files and way better at handling concurrent access when u scale up.

I encountered a similar situation with my own bot. I recommend implementing a logging system to track processed posts. I opted for SQLite for its simplicity and the fact that it doesn’t require a separate server. Create a table containing post IDs along with timestamps and check this table before sending out new posts. Since each Reddit post has a unique ID, it’s effective for this purpose. Be cautious with memory storage; while useful during development, it doesn’t persist through restarts, something I learned through experience.

Had the same problem with my news bot last year. I just used a text file to track processed post IDs. Bot reads the file first, checks against new posts, then adds new IDs after sending to Telegram. Super lightweight and doesn’t break when the bot restarts - no database needed. Just add a cleanup system so the file doesn’t get huge. I delete anything older than 30 days and it works great, even with thousands of posts tracked.