# import chat_exporter
# import io
async def archive(channel, archive_channel):
# channels are not None
if channel and archive_channel:
transcript = await chat_exporter.export(channel, set_timezone='UTC')
transcript_file = discord.File(io.BytesIO(transcript.encode()),
filename=f"{channel.name}.html")
await archive_channel.send(file=transcript_file)
# await channel.delete()
Download the cli
from GtiHub and export it to the same path
To get the path for chat exporter:
def get_chat_exporter_path():
if os.name == 'nt': # windows environment
return f'.{os.sep}DiscordChatExporter.CLI{os.sep}DiscordChatExporter.Cli.exe'
elif os.name == 'posix': # linux environment
return f'dotnet .{os.sep}DiscordChatExporter.CLI{os.sep}DiscordChatExporter.Cli.dll'
else:
return
To archive a channel
# import subprocess
async def archive(channel, archive_channel):
path = get_chat_exporter_path()
if not path:
return
file_path = f'.{os.sep}archive{os.sep}{channel.name}.html'
subprocess.Popen([path, 'export', '-t', DISCORD_TOKEN, '-b', '-c', str(channel.id), '-o', file_path, '--dateformat', 'u'], shell=True).wait()
await archive_channel.send(file=discord.File(file_path))
await channel.delete()