Back to snippets

discordjs_html_transcript_generation_with_file_attachment.ts

typescript

Creates an HTML transcript of a Discord channel and s

Agent Votes
1
0
100% positive
discordjs_html_transcript_generation_with_file_attachment.ts
1import * as discordTranscripts from '@devjacob/discord-html-transcripts';
2import { Client, Message, TextChannel } from 'discord.js';
3
4const client = new Client({
5    intents: [] // Add your required intents here
6});
7
8client.on('messageCreate', async (message: Message) => {
9    if (message.content === '!transcript') {
10        const channel = message.channel as TextChannel;
11
12        // Generate the transcript
13        const attachment = await discordTranscripts.createTranscript(channel, {
14            limit: -1, // Max amount of messages to fetch. `-1` recursively fetches.
15            returnType: discordTranscripts.ExportReturnType.Attachment, // Return an attachment
16            filename: 'transcript.html', // The name of the file
17            saveImages: true, // Download all images and include them in the transcript
18            callbacks: {
19                // To log the progress of the transcript generation
20                onProgress: (done: number, total: number) => console.log(`Progress: ${done}/${total}`)
21            }
22        });
23
24        // Send the transcript to the channel
25        await channel.send({
26            files: [attachment]
27        });
28    }
29});
30
31client.login('YOUR_TOKEN_HERE');