Skip to content

Repository files navigation

discord-html-transcript-discordjs

Generate natively styled HTML chat logs with your discord.js bot

npm discord-html-transcript License Discord

About

discord-html-transcript-discordjs is a discord.js library that generates offline HTML chat logs by retrieving the messages efficiently with your discord.js instance and passing them to the discord-html-transcript microservice to generate the file.

Features

  • ComponentsV2: Containers, Media Galleries, Sections, and more.
  • Markdown: Standard Markup, Mentions, Custom Emojis, and more.
  • Message Accessories: Attachments, Embeds, Polls, References, and more.
  • discord.js Integration: Use the generated file with discord.js directly.

Preview

discord-html-transcript

Getting Started

Prerequisites

  • Node.js v24.14.0 or higher
  • discord.js v14 or higher
  • discord-html-transcript v0.1.0-beta.6
  • Required Intents: GUILDS, GUILD_MEMBERS, MESSAGE_CONTENT.

Installation

npm i discord-html-transcript-discordjs

Configuration

Local Server (Default)

By default, the library downloads discord-html-transcript at runtime and places it inside your data directory.
(i.e., ~/.local/share/discord-html-transcript/)

Tip

If you wish to download the server manually:

  1. Download discord-html-transcript.
  2. Specify the server's path with an environment variable.
    (e.g., DISCORD_HTML_TRANSCRIPT_PATH=~/Downloads/discord-html-transcript-<version>-<platform>-<arch>)
const transcriber = new TranscriberClient(client, {
    // override the default host and port if necessary
    host: 'localhost', // default: '127.0.0.1'
    port: 8080         // default: 7000
});

Remote Server

If you wish to self-host discord-html-transcript:

const transcriber = new TranscriberClient(client, {
    url: 'https://server-url',  // required
    apiKey: 'server-secret-key' // required if the server requires authentication
});

Usage

Example: Slash Command

import {REQUIRED_INTENTS, TranscriberClient} from 'discord-html-transcript-discordjs';
import {Client, Events, MessageFlags, Routes, SlashCommandBuilder} from 'discord.js';

const client = new Client({intents: REQUIRED_INTENTS});
const transcriber = new TranscriberClient(client);

client.once(Events.ClientReady, (readyClient) => console.log(`Logged in as ${readyClient.user.tag}`));

client.on(Events.InteractionCreate, async (interaction) => {
    if (!interaction.isChatInputCommand()) return;

    const {channel} = interaction;

    // safely retrieve the channel
    if (!channel) {
        await interaction.reply({
            content: 'Failed to retrieve channel.',
            flags: MessageFlags.Ephemeral,
        });
        return;
    }

    // safely check the channel's type
    if (channel.isDMBased() || !channel.isTextBased) {
        await interaction.reply({
            content: 'This command can only be used in guild text channels.',
            flags: MessageFlags.Ephemeral,
        });
        return;
    }

    try {
        // acknowledge the interaction before Discord expires it
        // this is required in instances where a channel may have a large amount of messages to retrieve
        await interaction.deferReply({flags: MessageFlags.Ephemeral});

        const transcript = await transcriber.transcribe(channel, {
            attachment: {save_images: true},
        });

        const attachment = transcript.toAttachmentBuilder({name: channel.name});

        // send the generated transcript
        await interaction.followUp({files: [attachment]});
    } catch (error) {
        await interaction.followUp({content: 'Failed to generate transcript.'});
    }
});

await transcriber.start();
await client.login(process.env.DISCORD_BOT_TOKEN);

Contributing

If you found discord-html-transcript-discordjs useful, please consider giving it a 🌟!

Need help? Ask the Community!

Made With ❤️ By Omar Diaa

Fiverr Ko-fi

Releases

Sponsor this project

Contributors

Languages