3

Is it possible to create an archive of a channel using discord.py? I have tried following this: discrod.py Text channel history to HTML file, however it:

  1. Didn't send the file, no matter what I tried;
  2. When I opened the file through the browser, it didn't create the style you see in ticket bots.

I am using discord-components, so therefore chat_exporter doesn't work due to a bug. Does anyone know how to do this?

Mdog504
  • 37
  • 1
  • 7

2 Answers2

2

I think this is what you are looking for.

fileName = f"{ctx.channel.name}.txt"
with open(fileName, "w") as file:
    async for msg in ctx.channel.history(limit=None):
        file.write(f"{msg.created_at} - 
                   {msg.author.display_name}: 
                   {msg.clean_content}\n")

If you want to send the file do:

file = discord.File(fileName)
await ctx.send(file=file)

Of course, you can send the file to wherever you want, but this is just an example.

Bram
  • 511
  • 1
  • 6
  • 22
  • Works, however isn’t like the transcript you see on bots like Ticket Tool, where there is a file that is like a screenshot of the channel – Mdog504 Aug 26 '21 at 19:02
  • Well, that wasn't your question, I just gave you the answer on how to save a channel, and send it. I personally use this on my ticket system for my network. If you want to take screenshots, you need some sort of API to do that for you. I cannot help you with that. If it works I would highly appreciate it if you could upvote my answers, as it in fact did work. – Bram Aug 27 '21 at 07:16
0

The answer on The original post is now working however, the answer by Bram does also work. With the solution on the original post, chat-exporter will not work alongside discord-components, though there may be a fix for the issue soon (either by discord-components updating, or discord.py 2.0 releasing)

Mdog504
  • 37
  • 1
  • 7