Package: chat-exporter
DiscordChatExporterPyExport Discord chats with your discord.py (or fork) bots!Join Discord·Report Bug·Request FeatureInstallationTo install the library to your virtual environment, for bot usage, run the command:pipinstallchat-exporterTo clone the repository locally, run the command:gitclonehttps://github.com/mahtoid/DiscordChatExporterPy(back to top)UsageThere are currently 3 methods (functions) tochat-exporterwhich you can use to export your chat.Expand the blocks below to learn the functions, arguments and usages.Basic Usage.quick_export()is the simplest way of using chat-exporter.Using thequick_exportfunction will gather the history of the channel you give, build the transcript then post the file and embed directly to the channel - returning a message object gathered from the message it posted.This is mostly seen as a demo function, as opposed to a command you should actually use.Required Argument(s):channel:discord.TextChannelobject, whetherctx.channelor any channel you gather.Optional Argument(s):bot:commands.Botobject to gather members who are no longer in your guild.Return Argument:discord.Message: The messagequick_exportwill send, containing the embed and exported chat file.Example:importdiscordimportchat_exporterfromdiscord.extimportcommandsintents=discord.Intents.default()intents.members=Trueintents.message_content=Truebot=commands.Bot(command_prefix="!",intents=intents)...@bot.command()asyncdefsave(ctx:commands.Context):awaitchat_exporter.quick_export(ctx.channel)...Customisable Usage.export()is the most efficient and flexible method to export a chat using chat-exporter.Using theexportfunction will generate a transcript using the channel you pass in, along with using any of the custom kwargs passed in to set limits, timezone, 24h formats and more (listed below).This would be the main function to use within chat-exporter.Required Argument(s):channel:discord.TextChannelobject, whetherctx.channelor any channel you gather.Optional Argument(s):limit: Integer value to set the limit (amount of messages) the chat exporter gathers when grabbing the history (default=unlimited).tz_info: String value of aTZ Database nameto set a custom timezone for the exported messages (default=UTC)guild:discord.Guildobject which can be passed in to solve bugs for certain forksmilitary_time: Boolean value to set a 24h format for times within your exported chat (default=False | 12h format)fancy_times: Boolean value which toggles the 'fancy times' (Today|Yesterday|Day)before:datetime.datetimeobject which allows to gather messages from before a certain dateafter:datetime.datetimeobject which allows to gather messages from after a certain datebot:commands.Botobject to gather members who are no longer in your guild.Return Argument:transcript: The HTML build-up for you to construct the HTML File with Discord.Example:importio...@bot.command()asyncdefsave(ctx:commands.Context,limit:int=100,tz_info:str="UTC",military_time:bool=True):transcript=awaitchat_exporter.export(ctx.channel,limit=limit,tz_info=tz_info,military_time=military_time,bot=bot,)iftranscriptisNone:returntranscript_file=discord.File(io.BytesIO(transcript.encode()),filename=f"transcript-{ctx.channel.name}.html",)awaitctx.send(file=transcript_file)Raw Usage.raw_export()is for the crazy people who like to do their own thing when using chat-exporter.Using theraw_exportfunction will generate a transcript using the list of messages you pass in, along with using any of the custom kwargs passed in to set limits, timezone, 24h formats and more (listed below).This would be for people who want to filter what content to export.Required Argument(s):channel:discord.TextChannelobject, whetherctx.channelor any channel you gather (this is just for padding the header).messages: A list of Message objects which you wish to export to an HTML file.Optional Argument(s):tz_info: String value of aTZ Database nameto set a custom timezone for the exported messages (default=UTC)military_time: Boolean value to set a 24h format for times within your exported chat (default=False | 12h format)fancy_times: Boolean value which toggles the 'fancy times' (Today|Yesterday|Day)bot:commands.Botobject to gather members who are no longer in your guild.Return Argument:transcript: The HTML build-up for you to construct the HTML File with Discord.Example:importio...@bot.command()asyncdefpurge(ctx:commands.Context,tz_info:str,military_time:bool):deleted_messages=awaitctx.channel.purge()transcript=awaitchat_exporter.raw_export(ctx.channel,messages=deleted_messages,tz_info=tz_info,military_time=military_time,bot=bot,)iftranscriptisNone:returntranscript_file=discord.File(io.BytesIO(transcript.encode()),filename=f"transcript-{ctx.channel.name}.html",)awaitctx.send(file=transcript_file)(back to top)ScreenshotsGeneralDiscordChat-Exporter(back to top)Additional FunctionsLink FunctionDownloading exported chats can build up a bunch of unwanted files on your PC which can get annoying, additionally - not everyone wants to download content from Discord.Due to these pain, and many requests - I have built a fancy PHP script which will show the transcript file within a browser.quick_linkSimilar in design to `.quick_export()` this is a bit of a demo function to produce a link and to give you an embed.Required Argument(s):channel:discord.TextChannelobject, whetherctx.channelor any channel you gather.message: The Discord message containing the transcript fileReturn Argument:discord.Message: The messagequick_linkwill send, containing the embed.Example:importchat_exporter...@bot.command()asyncdefsave(ctx:commands.Context):message=awaitchat_exporter.quick_export(ctx.channel)awaitchat_exporter.quick_link(ctx.channel,message)linkA simple function to return the link you will need to view the transcript online.Required Argument(s):message: The Discord message containing the transcript fileReturn Argument:link: The link to view the transcript file onlineExample:importioimportchat_exporter...@bot.command()asyncdefsave(ctx:commands.Context):transcript=awaitchat_exporter.export(ctx.channel)iftranscriptisNone:returntranscript_file=discord.File(io.BytesIO(transcript.encode()),filename=f"transcript-{ctx.channel.name}.html",)message=awaitctx.send(file=transcript_file)link=awaitchat_exporter.link(message)awaitctx.send("Click this link to view the transcript online: "+link)Please note that the PHP script does NOT store any information.It simply makes a request to the given URL and echos (prints) the content for you to be able to view it.AttributionsThis project borrows CSS and HTML code fromTyrrrz's C# DiscordChatExporterrepository.(back to top)