messages fetch doesnt show up older messages

Hello! I run into a problem with my code:
async function fetchAllMessages(input, interactionUser) {
const channel = client.channels.cache.get(input);
let messages = [];
let amountPayout = 0

// Create message pointer
let message = await channel.messages
.fetch({ limit: 1 })
.then(messagePage => (messagePage.size === 1 ? messagePage.at(0) : null));

while (message) {
await channel.messages
.fetch({ limit: 100, before: message.id })
.then(messagePage => {
messagePage.forEach(msg => {
if (msg.embeds[0] && msg.embeds[0].title != 'Krautz - Familienkasse') {
let receivedEmbed = msg.embeds[0]
const descr = receivedEmbed.description.split(" ");
let id = descr[2].replace("<@", "").replace(">", "")
const user = client.users.cache.get(id)
for (let field of receivedEmbed.fields) {
if (field.name == ":moneybag: Auszahlung" && user == interactionUser) {
let int = parseInt(field.value.replace("$ ", ""))
amountPayout = amountPayout + int
console.log("+ " + int + " Fisch: " + amountPayout)

msg.delete()
}
}
}
//messages.push(msg)
});

// Update our message pointer to be last message in page of messages
message = 0 < messagePage.size ? messagePage.at(messagePage.size - 1) : null;
})
}
return amountPayout
}
async function fetchAllMessages(input, interactionUser) {
const channel = client.channels.cache.get(input);
let messages = [];
let amountPayout = 0

// Create message pointer
let message = await channel.messages
.fetch({ limit: 1 })
.then(messagePage => (messagePage.size === 1 ? messagePage.at(0) : null));

while (message) {
await channel.messages
.fetch({ limit: 100, before: message.id })
.then(messagePage => {
messagePage.forEach(msg => {
if (msg.embeds[0] && msg.embeds[0].title != 'Krautz - Familienkasse') {
let receivedEmbed = msg.embeds[0]
const descr = receivedEmbed.description.split(" ");
let id = descr[2].replace("<@", "").replace(">", "")
const user = client.users.cache.get(id)
for (let field of receivedEmbed.fields) {
if (field.name == ":moneybag: Auszahlung" && user == interactionUser) {
let int = parseInt(field.value.replace("$ ", ""))
amountPayout = amountPayout + int
console.log("+ " + int + " Fisch: " + amountPayout)

msg.delete()
}
}
}
//messages.push(msg)
});

// Update our message pointer to be last message in page of messages
message = 0 < messagePage.size ? messagePage.at(messagePage.size - 1) : null;
})
}
return amountPayout
}
Its working good, but when there are older messages with embeds they don't add them why?
5 Replies
d.js docs
d.js docs3y ago
• What's your exact discord.js npm list discord.js and node node -v version? • Post the full error stack trace, not just the top part! • Show your code! • Explain what exactly your issue is. • Not a discord.js issue? Check out #useful-servers.
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Verena
VerenaOP3y ago
But the messages is not older than yesterday So whats the issue with my code? sometimes he doesnt reconize messages So i run the command he fetch the channel messages but older embeds does not go through the loop
Verena
VerenaOP3y ago
The function does not get the first message in the screenshot
Verena
VerenaOP3y ago
So what i want to do is that the function loop all messages in this channel, and grabs every message with an embed then when the embed has specific title and field.name the function will grab the value from the field and adds it to the variable then the function deletes this messages. After that we will return me the result of all values together But somehow older messages will not be deleted am i dumb i am wait okay, maybe i am dumb because of no sleep, thanks anyways haha.
Want results from more Discord servers?
Add your server