discord-html-transcripts-fix
v1.0.0
Published
A nicely formatted html transcript generator for discord.js. Bugfix fork with support for the latest discord.js and Components v2.
Readme
discord-html-transcripts (Bugfix Fork)
This is a fork of discord-html-transcripts with bug fixes for compatibility with the latest discord.js version and Components v2.
Changes compared to the original
- Fixed compatibility with the latest discord.js version
- Added support for Discord Components v2
Requirements
This package requires react and react-dom as peer dependencies. Install them before using this package:
npm install react@^19.2.3 react-dom@^19.2.3Usage
Example usage using the built in message fetcher.
const discordTranscripts = require('discord-html-transcripts');
// or (if using typescript) import * as discordTranscripts from 'discord-html-transcripts';
const channel = message.channel; // or however you get your TextChannel
// Must be awaited
const attachment = await discordTranscripts.createTranscript(channel);
channel.send({
files: [attachment],
});Or if you prefer, you can pass in your own messages.
const discordTranscripts = require('discord-html-transcripts');
// or (if using typescript) import * as discordTranscripts from 'discord-html-transcripts';
const messages = someWayToGetMessages(); // Must be Collection<string, Message> or Message[]
const channel = someWayToGetChannel(); // Used for ticket name, guild icon, and guild name
// Must be awaited
const attachment = await discordTranscripts.generateFromMessages(messages, channel);
channel.send({
files: [attachment],
});Configuration
Both methods of generating a transcript allow for an option object as the last parameter. All configuration options are optional!
Built in Message Fetcher
const attachment = await discordTranscripts.createTranscript(channel, {
limit: -1, // Max amount of messages to fetch. `-1` recursively fetches.
returnType: 'attachment', // Valid options: 'buffer' | 'string' | 'attachment' Default: 'attachment' OR use the enum ExportReturnType
filename: 'transcript.html', // Only valid with returnType is 'attachment'. Name of attachment.
saveImages: false, // Download all images and include the image data in the HTML (allows viewing the image even after it has been deleted) (! WILL INCREASE FILE SIZE !)
footerText: "Exported {number} message{s}", // Change text at footer, don't forget to put {number} to show how much messages got exported, and {s} for plural
callbacks: {
// register custom callbacks for the following:
resolveChannel: (channelId: string) => Awaitable<Channel | null>,
resolveUser: (userId: string) => Awaitable<User | null>,
resolveRole: (roleId: string) => Awaitable<Role | null>,
resolveImageSrc: (
attachment: APIAttachment,
message: APIMessage
) => Awaitable<string | null | undefined>
},
poweredBy: true, // Whether to include the "Powered by discord-html-transcripts" footer
hydrate: true, // Whether to hydrate the html server-side
filter: (message) => true // Filter messages, e.g. (message) => !message.author.bot
});Providing your own messages
const attachment = await discordTranscripts.generateFromMessages(messages, channel, {
// Same as createTranscript, except no limit or filter
});Credits
Original package by ItzDerock. Styles from @derockdev/discord-components.
