Skip to main content

A simple Discord chat exporter for Python Discord bots.

Project description

version license language

DiscordChatExporterPy is a Python plugin for your discord.py bot, allowing you to export a discord channels history within a guild.

Installing

To install the library to your bot, run the command:

pip install chat-exporter

To install the repository, run the command:

git clone https://github.com/mahtoid/DiscordChatExporterPy

Usage

Basic Usage

import discord
import chat_exporter
from discord.ext import commands

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

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


@bot.event
async def on_ready():
    print("Live: " + bot.user.name)
    chat_exporter.init_exporter(bot)


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

if __name__ == "__main__":
    bot.run("BOT_TOKEN_HERE")

Optional: If you want the transcript to display Members (Role) Colours then enable the Members Intent.

Customisable Usage

import io

...

@bot.command()
async def save(ctx, limit: int, tz_info):
    transcript = await chat_exporter.export(ctx.channel, limit, tz_info)

    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)

Optional: limit and tz_info are both optional, but can be used to limit the amount of messages transcribed or set a ‘local’ (pytz) timezone for the bot to transcribe message times to.

Raw Usage

import io

...

@bot.command()
async def purge(ctx, tz_info):
    deleted_messages = await ctx.channel.purge()

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

    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)

Optional: tz_info is optional, but can be used to set a ‘local’ (pytz) timezone for the bot to transcribe message times to.

Screenshots

https://raw.githubusercontent.com/mahtoid/DiscordChatExporterPy/master/.screenshots/channel_output.png https://raw.githubusercontent.com/mahtoid/DiscordChatExporterPy/master/.screenshots/html_output.png

Attributions

This project borrows CSS and HTML code from Tyrrrz’s C# DiscordChatExporter repository.

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

chat_exporter-1.3.0.7.tar.gz (32.6 kB view details)

Uploaded Source

Built Distribution

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

chat_exporter-1.3.0.7-py3-none-any.whl (39.5 kB view details)

Uploaded Python 3

File details

Details for the file chat_exporter-1.3.0.7.tar.gz.

File metadata

  • Download URL: chat_exporter-1.3.0.7.tar.gz
  • Upload date:
  • Size: 32.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for chat_exporter-1.3.0.7.tar.gz
Algorithm Hash digest
SHA256 64fe0bfde191ef3a8005f86752445d6b097f34bfdada8f29f9f51b6a0c503e28
MD5 9ee2fd4260d20d35b275da8500601a09
BLAKE2b-256 d209784b8b93b20fcaf0f5c293c9f1ad95de50182f0e940feead1acf22225805

See more details on using hashes here.

File details

Details for the file chat_exporter-1.3.0.7-py3-none-any.whl.

File metadata

  • Download URL: chat_exporter-1.3.0.7-py3-none-any.whl
  • Upload date:
  • Size: 39.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.3.0 pkginfo/1.7.0 requests/2.25.1 setuptools/52.0.0 requests-toolbelt/0.9.1 tqdm/4.56.0 CPython/3.8.6

File hashes

Hashes for chat_exporter-1.3.0.7-py3-none-any.whl
Algorithm Hash digest
SHA256 410cb593641ccec546d791685c15d5c677b0a223637a7f73ec7502917b92ea6e
MD5 3c29eee8d3cc24c69735be9647915046
BLAKE2b-256 e11b07980025bb689a45f95d524167f51d4c2a489c2d6a52b9b6c1100434e651

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