Fetch messages after a message with including initialMessage

let messages = await dmChannel.messages.fetch();
const initialMessage = messages.find(
(x) =>
x.components[0] &&
x.components[0].components &&
x.components[0].components.find(
(x) => x.type === ComponentType.StringSelect,
),
);

messages = new Collection([
[initialMessage.id, initialMessage],
...(await dmChannel.messages.fetch({ after: initialMessage.id })).reverse(),
]);
let messages = await dmChannel.messages.fetch();
const initialMessage = messages.find(
(x) =>
x.components[0] &&
x.components[0].components &&
x.components[0].components.find(
(x) => x.type === ComponentType.StringSelect,
),
);

messages = new Collection([
[initialMessage.id, initialMessage],
...(await dmChannel.messages.fetch({ after: initialMessage.id })).reverse(),
]);
I dont know if i can convert the collection to array. slice them and convert them back. this is the current way, but i think its not the best, because of duplicated fetch# maybe. someone heas
5 Replies
d.js toolkit
d.js toolkit8mo 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
Yinoguns
Yinoguns8mo ago
re-opened You could use the timestamp of the found message and then filter to those that came after; that'd save you the second fetch, no?
f1fty
f1ftyOP8mo ago
oh my god makes sense thanks
Yinoguns
Yinoguns8mo ago
NP jiralite opened this btw, so you can probs ping em when happy
f1fty
f1ftyOP8mo ago
@Jiralite can be marked as resolved again
Want results from more Discord servers?
Add your server