How To Make Ticket Transcripts Discord.js V14?

Install dependencies:

`npm i discord.js`

`npm i discord-html-transcripts`

Enable intents in your client:

`Guilds`

`GuildMessages`

`MessageContent`

Create a ticket channel and store its channel ID if needed

Import the transcript package:

`const transcripts = require(‘discord-html-transcripts’);`

Generate a transcript when the ticket is closed:

`const transcript = await transcripts.createTranscript(ticketChannel, { limit: -1, returnType: ‘attachment’ });`

Send the transcript to a log channel:

`await logChannel.send({ files: [transcript] });`

Optionally send the transcript to the ticket opener:

`await user.send({ files: [transcript] });`

Delete or archive the ticket channel after sending the transcript

Example close handler:

`const transcripts = require(‘discord-html-transcripts’);`

`client.on(‘interactionCreate’, async interaction => {`

`if (!interaction.isButton()) return;`

`if (interaction.customId !== ‘close_ticket’) return;`

`const ticketChannel = interaction.channel;`

`const transcript = await transcripts.createTranscript(ticketChannel, { limit: -1, returnType: ‘attachment’ });`

`const logChannel = interaction.guild.channels.cache.get(‘LOG_CHANNEL_ID’);`

`await logChannel.send({ files: [transcript] });`

`await interaction.reply({ content: ‘Ticket closed and transcript saved.’, ephemeral: true });`

`await ticketChannel.delete();`

`});`

Use `limit: -1` to include all messages

Use `returnType: ‘attachment’` to send the transcript as a file

Replace `LOG_CHANNEL_ID` with your transcript log channel ID

Make sure the bot has permission to read messages and send files

Make sure the bot has permission to view the ticket channel before generating the transcript

Suggested for You

Trending Today