Is there a way to save deleted messages and use them in transcript?

const fs = require('fs');
const path = require('path');

async function generateTranscript(channel) {
const messages = await channel.messages.fetch({ limit: 100 });
const sortedMessages = messages.sort((a, b) => a.createdTimestamp - b.createdTimestamp);
const transcript = sortedMessages.map(msg => {
const date = new Date(msg.createdTimestamp);
const moscowTime = date.toLocaleString('ru-RU', { timeZone: 'Europe/Moscow' });
return `*${moscowTime}* - **${msg.author.tag}**: ${msg.content}`;
}).join('\n---\n');
const fileName = `${channel.name}-${channel.topic.match(/<@(\d+)>/)[1]}.txt`;
const filePath = path.join(__dirname, '../transcripts', fileName);

fs.writeFileSync(filePath, transcript);
return filePath;
}

module.exports = { generateTranscript };
const fs = require('fs');
const path = require('path');

async function generateTranscript(channel) {
const messages = await channel.messages.fetch({ limit: 100 });
const sortedMessages = messages.sort((a, b) => a.createdTimestamp - b.createdTimestamp);
const transcript = sortedMessages.map(msg => {
const date = new Date(msg.createdTimestamp);
const moscowTime = date.toLocaleString('ru-RU', { timeZone: 'Europe/Moscow' });
return `*${moscowTime}* - **${msg.author.tag}**: ${msg.content}`;
}).join('\n---\n');
const fileName = `${channel.name}-${channel.topic.match(/<@(\d+)>/)[1]}.txt`;
const filePath = path.join(__dirname, '../transcripts', fileName);

fs.writeFileSync(filePath, transcript);
return filePath;
}

module.exports = { generateTranscript };
11 Replies
d.js toolkit
d.js toolkit3mo ago
- What's your exact discord.js npm list discord.js and node node -v version? - Not a discord.js issue? Check out #other-js-ts. - Consider reading #how-to-get-help to improve your question! - Explain what exactly your issue is. - Post the full error stack trace, not just the top part! - Show your code! - Issue solved? Press the button! - Marked as resolved by OP
1
1OP3mo ago
I want to make it like this, but i`m not sure if its the best way
client.on('messageDelete', message => {
deletedMessages.push({
content: message.content,
author: message.author.tag,
createdTimestamp: message.createdTimestamp,
deletedTimestamp: Date.now()
});
});
client.on('messageDelete', message => {
deletedMessages.push({
content: message.content,
author: message.author.tag,
createdTimestamp: message.createdTimestamp,
deletedTimestamp: Date.now()
});
});
and store them in some kind of array like
const deletedMessages = [];
const deletedMessages = [];
Amgelo
Amgelo3mo ago
with what part of djs do you need help for this? this sounds more like a file saving question
1
1OP3mo ago
Because I`ll send the file as attacment into logs like this
1
1OP3mo ago
No description
Amgelo
Amgelo3mo ago
and you want to know how to send a file?
1
1OP3mo ago
no, I want to know how to store deleted messages from the ticket to then send them in transcript
Amgelo
Amgelo3mo ago
djs doesn't handle storage or transcript management that part is up to you djs only manages the "discord communication" part
1
1OP3mo ago
damn aight then
Amgelo
Amgelo3mo ago
you can ask in #other-js-ts if you have any issue with your setup but here it's only for djs questions
1
1OP3mo ago
ok ok
Want results from more Discord servers?
Add your server