How to build a Discord bot that records all server activity

I’m trying to make a Discord bot using Python that can track and save all server activity to a file. I need it to capture things like new messages, when people edit their messages, deleted content, and when invite links get created. I found the .on_message() event but I’m not sure how to actually extract the message content from it. Can someone help me figure this out? This is for our school club’s Discord server because we need to keep records of all conversations for our teachers to review. The bot will run on our school’s computer system so everything stays secure.

Had the same storage problems when I built mine. One thing everyone’s missing - Discord’s audit log API fills in gaps your regular event tracking misses, especially for admin actions. You’ll need View Audit Log permission though. Heads up: threads and forum posts use different event handlers than normal channels. And watch for infinite loops if your logging bot reacts to itself. I switched to JSON files instead of plain text - way easier when teachers want data for specific dates or users. Oh, and school networks sometimes block Discord gateway connections, so test everything before you deploy.

To build your Discord bot, you’ll need to work with more than just the on_message event. You can access the message content using message.content and message.author from the event object. Additionally, make sure to implement on_message_edit and on_message_delete to capture edited and deleted messages. It’s important to note that Discord does not retain the content of deleted messages, so you’ll need to cache the messages your bot receives to log this information.

For tracking invites, implement the on_invite_create and on_invite_delete events. Consider using a database like SQLite to store the data instead of plain text files, as you’ll handle a considerable amount of information. Make sure your bot is granted the necessary permissions and intents in the Discord developer portal, particularly the message content intent. Just a heads up: if your server is busy, this can become resource-intensive, so it’s wise to incorporate error handling and possibly rotate your log files to manage the size.

heads up - logging messages could break discord’s ToS depending on your setup. check their developer policy first. for coding, use discord.py and enable privileged gateway intents in bot settings or it won’t work.

Had the same privacy issues setting up monitoring for our gaming community. Besides the technical stuff already mentioned, document what data you’re collecting and how long you keep it - schools usually want this documented. Found out the hard way that embeds and attachments need special handling since they don’t show up in message.content. Set up user opt-out options even for educational use - some students have real privacy concerns. The logging can slow things down when everyone’s online, so test it first. What worked for me was creating a separate channel where the bot posts daily summaries instead of dumping everything into files - way easier for teachers to review than digging through raw logs.

Building a bot for all that tracking gets messy quick - rate limits and storage headaches like everyone’s saying.

Skip the Discord.py hassle and file management nightmare. I’d use Latenode to automate everything. Set up webhooks to grab Discord events and run them through workflows that handle processing, storage, and report formatting for teachers.

Best part? No rate limit worries, no file rotation headaches, no keeping bots alive 24/7 on school servers. Latenode handles the heavy lifting while you focus on what data you actually need.

I’ve done similar compliance logging setups at work. The automation parses messages, tracks edits/deletions, and spits out daily summaries. Way cleaner than wrestling with Python scripts and database connections.

For invite tracking, you can automate periodic snapshots and comparisons without those unreliable Discord events people mentioned.

I’ve done something similar for our server. You’re missing the message content intent in your bot settings on Discord’s developer portal - without it, message.content stays empty. Also set up file handling with timestamps and rotate your logs since they get huge fast. I hit rate limit issues when the server got busy, so add exception handling around file writes. For invite tracking, store a snapshot of current invites at startup and compare when events fire - Discord’s invite events are unreliable otherwise.