Unless they changed it, small scale bots (10 servers or less, large bots need approval) can see every message event in every channel they have access to using the websocket API. They can also query older messages. It's pretty straightforward once you know how to use the API.
From there it's no longer a Discord problem, as you just need to export that data somewhere. There's bots which already partialy do this. There's bots that log edits & deletes for moderators to review and bots like TicketTool (https://tickettool.xyz/) let you create special one-off channels (tickets) that you can export to html on closure too.