My plan is to create a bot that will store all messages sent in a channel into a txt file on my computer. However, the challenge is that since my computer is not always on when the bot is running, there are gaps in the stored messages in the .txt file. I am working on a solution where the bot will capture all messages sent while it was offline and save them in the file. To achieve this, I have set up a txt file to save the message IDs of each message, essentially creating a file with just one message ID at a time. At bot startup, a boolean variable is initialized as false and will be changed to true once the startup process is completed. Here's what I have so far:
var latest;
var beenRunning = false;
bot.on('message', msg => {
latest = msg.id;
if(beenRunning == false) {
msg.channel.messages.fetch(latest, {limit: 100})
.then(messages =>
//code to retrieve messages since last online session
)
.catch(console.error);
beenRunning = true;
}
else {
messageTest(msg);
}
fs.writeFile('lastMsg.txt', latest, (err) => {
if (err) throw err;
})
});
I'm currently facing an issue with using the fetch() method to retrieve every message sent since going offline. Can anyone provide guidance on how I can accomplish this?