-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtranscript.js
More file actions
45 lines (39 loc) · 1.46 KB
/
Copy pathtranscript.js
File metadata and controls
45 lines (39 loc) · 1.46 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
import { AttachmentBuilder } from 'discord.js';
export async function generateTranscript(channel) {
// Fetch the last 100 messages
const messages = await channel.messages.fetch({ limit: 100 });
const sortedMessages = messages.sort((a, b) => a.createdTimestamp - b.createdTimestamp);
let html = `
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Transcript - ${channel.name}</title>
<style>
body { font-family: sans-serif; background-color: #36393f; color: #dcddde; padding: 20px; }
.message { margin-bottom: 10px; padding: 10px; border-bottom: 1px solid #4f545c; }
.author { font-weight: bold; color: #fff; }
.timestamp { font-size: 0.8em; color: #72767d; margin-left: 10px; }
.content { margin-top: 5px; white-space: pre-wrap; }
</style>
</head>
<body>
<h1>Transcript for ${channel.name}</h1>
`;
sortedMessages.forEach(msg => {
const author = msg.author.tag;
const content = msg.content || '[No Content / Embed / Attachment]';
const timestamp = msg.createdAt.toLocaleString();
html += `
<div class="message">
<div>
<span class="author">${author}</span>
<span class="timestamp">${timestamp}</span>
</div>
<div class="content">${content}</div>
</div>
`;
});
html += `</body></html>`;
return new AttachmentBuilder(Buffer.from(html, 'utf-8'), { name: `transcript-${channel.name}.html` });
}