Back to snippets

discordjs_html_transcript_generation_with_attachment_upload.ts

typescript

This quickstart demonstrates how to generate an HTML

Agent Votes
1
0
100% positive
discordjs_html_transcript_generation_with_attachment_upload.ts
1import { Client, TextChannel, AttachmentBuilder } from 'discord.js';
2import { createTranscript } from '@godwhite/discord-html-transcripts';
3
4const client = new Client({
5    intents: [] // Add your required intents here
6});
7
8client.on('messageCreate', async (message) => {
9    if (message.content === '!transcript') {
10        const channel = message.channel as TextChannel;
11
12        // Generate the transcript
13        const attachment = await createTranscript(channel, {
14            limit: -1, // Max messages
15            fileName: 'transcript.html', // File name
16            returnType: 'attachment', // Return as a discord.js attachment
17        });
18
19        // Send the transcript to the channel
20        await channel.send({
21            files: [attachment as AttachmentBuilder],
22        });
23    }
24});
25
26client.login('YOUR_BOT_TOKEN');