Updating paginated message pages while the handler is running

I'm trying to make a paginated message that can be updated after its creation. My command currently: 1. Responds with the paginated message with data from the database 2. Fetches new data from an API in the background 3. Updates the pages of the paginated message with this new data I'm currently using the following code to handle the "background task" logic:
paginatedMessage.setPages([]);

for (const recordsChunk of chunk(records, 10)) {
// Add pages with information from the API to the paginated message
}

// Attempt to retain the page number of the paginated message with stale data
const pageIndex = Math.max(Math.min(paginatedMessage.index, paginatedMessage.pages.length - 1), 0);

const page = await paginatedMessage.resolvePage(paginatedMessage.response, user, pageIndex);

await safelyReplyToInteraction({
messageOrInteraction: paginatedMessage.response,
interactionEditReplyContent: page,
interactionReplyContent: { content: "This error should not be able to happen...", ephemeral: true },
componentUpdateContent: page,
messageMethod: "edit",
messageMethodContent: page,
});
paginatedMessage.setPages([]);

for (const recordsChunk of chunk(records, 10)) {
// Add pages with information from the API to the paginated message
}

// Attempt to retain the page number of the paginated message with stale data
const pageIndex = Math.max(Math.min(paginatedMessage.index, paginatedMessage.pages.length - 1), 0);

const page = await paginatedMessage.resolvePage(paginatedMessage.response, user, pageIndex);

await safelyReplyToInteraction({
messageOrInteraction: paginatedMessage.response,
interactionEditReplyContent: page,
interactionReplyContent: { content: "This error should not be able to happen...", ephemeral: true },
componentUpdateContent: page,
messageMethod: "edit",
messageMethodContent: page,
});
This works but after the update happens the components of the paginated message don't respond anymore and result in This interaction failed. Is there a different way to go about this? Because I essentially just need to reload/refresh the current page.
1 Reply
Silver
SilverOP5w ago
it seems like removing the listeners of the old paginated message and creating a new instance works seems the best sollution for this is to use the provided .clone() method for this
Want results from more Discord servers?
Add your server