A Discord bot to archive your Discord channels into HTML files.
Invite the Discord bot to your Discord server with the link at the bottom of this page. Be sure not to change any of the permissions. Once invited, navigate to the channel you want to archive and send ".archive X" where X (max 1000) is the amount of amount of messages you want to archive. The bot will respond shortly with a HTML file with the last X messages sent in the channel. From there you can download the file onto your computer and load it in your browser to view it. Leaving out the number of messages to archive (aka X) will archive the last 500 messages. To archive more than 1000 messages, you will need to host your own instance of the bot. Instructions are on the project README.
The bot listens to the command ".archive X" through the discord.py package. When a user runs that command, it retrieves the last X messages sent in the channel the command was sent in through the discord.py package. Once the Discord API retrieves the X amount of messages, a dictionary is created which stores all the relevant info needed to construct the HTML file. This includes the server and channel name, the messages, images, and files that have been sent, and any profile pictures/usernames. This dictionary gets passed into a function which ultimately generates the HTML. Finally, the HTML file gets sent to the channel that ".archive" was sent in using the discord.py package.
I used the discord.py library to listen to the ".archive X" command, to retrieve all the data (server/channel names, messages, images, files, user info) needed to generate the HTML, and to send the HTML file back to the user.
I used the python-dotenv library to load the bot token from the .env file as a best practice when dealing with environment variables.
I used the os library to delete the HTML file export from the server after it was sent to it's channel. I also used it in conjunction with the python-dotenv package to retrieve the bot token.