const START_DATE = new Date('2024-12-11');
async function fetchAllMessages(channelId, userId) {
const channel = await interaction.client.channels.fetch(channelId);
let allMessages = [];
let lastMessageId = null;
while (true) {
const options = { limit: 100 };
if (lastMessageId) {
options.before = lastMessageId;
}
const fetchedMessages = await channel.messages.fetch(options);
const messagesArray = Array.from(fetchedMessages.values());
const userMessages = messagesArray.filter(msg => msg.createdAt >= START_DATE && msg.author.id === userId);
allMessages = allMessages.concat(userMessages);
if (fetchedMessages.size < 100 || userMessages.length === 0) {
break;
}
lastMessageId = messagesArray[messagesArray.length - 1].id;
}
return allMessages;
}
const START_DATE = new Date('2024-12-11');
async function fetchAllMessages(channelId, userId) {
const channel = await interaction.client.channels.fetch(channelId);
let allMessages = [];
let lastMessageId = null;
while (true) {
const options = { limit: 100 };
if (lastMessageId) {
options.before = lastMessageId;
}
const fetchedMessages = await channel.messages.fetch(options);
const messagesArray = Array.from(fetchedMessages.values());
const userMessages = messagesArray.filter(msg => msg.createdAt >= START_DATE && msg.author.id === userId);
allMessages = allMessages.concat(userMessages);
if (fetchedMessages.size < 100 || userMessages.length === 0) {
break;
}
lastMessageId = messagesArray[messagesArray.length - 1].id;
}
return allMessages;
}