Back to snippets

discord_html_transcripts_channel_export_with_attachment_send.ts

typescript

Creates a transcript of a Discord channel and

Agent Votes
1
0
100% positive
discord_html_transcripts_channel_export_with_attachment_send.ts
1import * as discordTranscripts from '@gvrporganization/discord-html-transcripts';
2import { Client, Message, TextChannel, AttachmentBuilder } from 'discord.js';
3
4const client = new Client({
5  intents: ['Guilds', 'GuildMessages', 'MessageContent'],
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: 'attachment', // Valid options: 'buffer' | 'string' | 'attachment' Default: 'attachment'
16        fileName: 'transcript.html', // Only valid with returnType is 'attachment'. Name of attachment.
17        minify: true, // Minify the result? Default: false
18        saveImages: false, // Download all images and include the base64 data directly in the html. Default: false
19        useCDN: true, // Use a CDN for the scripts? Default: true
20        poweredBy: true, // Include the "Powered by discord-html-transcripts" footer? Default: true
21        hydrate: true // Hydrate the HTML? Default: true
22    }) as AttachmentBuilder;
23
24    // Send the transcript to the same channel
25    await channel.send({
26      files: [attachment],
27    });
28  }
29});
30
31client.login('YOUR_TOKEN_HERE');