Skip to main content

A simple Discord chat exporter for Python Discord bots.

Project description

Py-Discord-HTML-Transcripts


Requirements

discord.py v2.4.0 or later


Installation

To install the library to your virtual environment, for bot usage, run the command:

pip install py-discord-html-transcripts

Usage

There are currently 3 methods (functions) to chat-exporter which 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 the quick_export function 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.TextChannel object, whether ctx.channel or any channel you gather.

Optional Argument(s):
bot: commands.Bot object to gather members who are no longer in your guild.

Return Argument:
discord.Message: The message quick_export will send, containing the embed and exported chat file.

Example:

import discord
import chat_exporter
from discord.ext import commands

intents = discord.Intents.default()
intents.members = True
intents.message_content = True

bot = commands.Bot(command_prefix="!", intents=intents)

...

@bot.command()
async def save(ctx: commands.Context):
    await chat_exporter.quick_export(ctx.channel)

...
Customisable Usage

.export() is the most efficient and flexible method to export a chat using chat-exporter.

Using the export function 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.TextChannel object, whether ctx.channel or 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 a TZ Database name to set a custom timezone for the exported messages (default=UTC)
guild: discord.Guild object which can be passed in to solve bugs for certain forks
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)
before: datetime.datetime object which allows to gather messages from before a certain date after: datetime.datetime object which allows to gather messages from after a certain date bot: commands.Bot object 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:

import io

...

@bot.command()
async def save(ctx: commands.Context, limit: int = 100, tz_info: str = "UTC", military_time: bool = True):
    transcript = await chat_exporter.export(
        ctx.channel,
        limit=limit,
        tz_info=tz_info,
        military_time=military_time,
        bot=bot,
    )

    if transcript is None:
        return

    transcript_file = discord.File(
        io.BytesIO(transcript.encode()),
        filename=f"transcript-{ctx.channel.name}.html",
    )

    await ctx.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 the raw_export function 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.TextChannel object, whether ctx.channel or 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 a TZ Database name to 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.Bot object 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:

import io

...

@bot.command()
async def purge(ctx: commands.Context, tz_info: str, military_time: bool):
    deleted_messages = await ctx.channel.purge()

    transcript = await chat_exporter.raw_export(
        ctx.channel,
        messages=deleted_messages,
        tz_info=tz_info,
        military_time=military_time,
        bot=bot,
    )

    if transcript is None:
        return

    transcript_file = discord.File(
        io.BytesIO(transcript.encode()),
        filename=f"transcript-{ctx.channel.name}.html",
    )

    await ctx.send(file=transcript_file)

(back to top)


Screenshots

General
    Discord
    Chat-Exporter

(back to top)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

py_discord_html_transcripts-2.3.1.tar.gz (36.5 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

py_discord_html_transcripts-2.3.1-py3-none-any.whl (49.1 kB view details)

Uploaded Python 3

File details

Details for the file py_discord_html_transcripts-2.3.1.tar.gz.

File metadata

File hashes

Hashes for py_discord_html_transcripts-2.3.1.tar.gz
Algorithm Hash digest
SHA256 9c336e6c2305b4760a016cb0b425692e9fd4014b50f5e68ae7358aef5468d0fb
MD5 e909bbbcca7b6f822316b170bf1370d6
BLAKE2b-256 eb758817a572efe3d1ce6697443b23220b3a049fa8f45c75066a3752668689cf

See more details on using hashes here.

File details

Details for the file py_discord_html_transcripts-2.3.1-py3-none-any.whl.

File metadata

File hashes

Hashes for py_discord_html_transcripts-2.3.1-py3-none-any.whl
Algorithm Hash digest
SHA256 887a1f33deb7c3debf847f80e6890dc77ef54d63f4ef880d304cdbc404aea367
MD5 8449eab68f47d6fe00ec8f9f43a1478b
BLAKE2b-256 e280139972054a0d42b1ae9ce603deba13a485f419b3ae55d19db324b7a844a1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page