${msg.author.tag}
(${time})
${content}
`;
// Pièces jointes
if (msg.attachments.size > 0) {
msg.attachments.forEach((att) => {
if (att.contentType?.startsWith('image/')) {
html += `
`;
} else {
html += `
`;
}
});
}
// Stickers
if (msg.stickers.size > 0) {
msg.stickers.forEach((sticker) => {
if (sticker.format === StickerFormatType.LOTTIE) {
html += `
[Sticker Lottie non supporté]
`;
return;
}
const url = `https://cdn.discordapp.com/stickers/${sticker.id}.png`;
html += `
${sticker.name}
`;
});
}
// Embeds
if (msg.embeds.length > 0) {
msg.embeds.forEach((embed) => {
html += `
`;
if (embed.title) html += `
${embed.title}
`;
if (embed.description) html += `
${embed.description}
`;
if (embed.url)
html += `
`;
if (embed.thumbnail?.url) {
html += `

`;
}
html += `
`;
});
}
html += `
`;
}
html += ``;
const transcriptsDir = path.join(__dirname, '../transcripts');
if (!fs.existsSync(transcriptsDir)) fs.mkdirSync(transcriptsDir);
const filePath = path.join(transcriptsDir, `${channel.id}.html`);
fs.writeFileSync(filePath, html, 'utf8');
// Logs
const logChannel = await channel.client.channels
.fetch(config.logsChannel)
.catch(() => null);
if (logChannel) {
const embed = new EmbedBuilder()
.setTitle('🔒 Ticket fermé')
.addFields(
{ name: 'Salon', value: `${channel.name}`, inline: true },
{
name: 'Fermé par',
value: user ? `${user.tag} (${user.id})` : 'Automatique',
inline: true,
},
{
name: 'Transcript',
value: `http://localhost:3000/transcript/${channel.id}`,
}
)
.setColor(0xe74c3c)
.setTimestamp();
await logChannel.send({ embeds: [embed] });
}
}
async function closeTicketWithTranscript(channel, user) {
await generateTranscript(channel, user);
closeTicket(channel.id);
await channel.delete().catch(() => {});
}
module.exports = { closeTicketWithTranscript };