Paginated message not editing reply (always seems to reply)

const display = new PaginatedMessage({
template: templateEmbed,
pageIndexPrefix: 'Case',
actions: [
{
customId: 'view_case',
style: ButtonStyle.Success,
type: ComponentType.Button,
emoji: ':mag_right:',
run(context) {
context.collector.stop();
CaseCommand.createCaseEmbed(cases[context.handler.index], interaction, collection);
}
},
...PaginatedMessage.defaultActions
]
});
const display = new PaginatedMessage({
template: templateEmbed,
pageIndexPrefix: 'Case',
actions: [
{
customId: 'view_case',
style: ButtonStyle.Success,
type: ComponentType.Button,
emoji: ':mag_right:',
run(context) {
context.collector.stop();
CaseCommand.createCaseEmbed(cases[context.handler.index], interaction, collection);
}
},
...PaginatedMessage.defaultActions
]
});
CaseCommand.createCaseEmbed creates another paginated message, and runs it.
C:\Users\x\Documents\Clanware\clanware-bot\node_modules\@discordjs\rest\dist\index.js:687
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[40060]: Interaction has already been acknowledged.
at handleErrors (C:\Users\x\Documents\Clanware\clanware-bot\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (C:\Users\x\Documents\Clanware\clanware-bot\node_modules\@discordjs\rest\dist\index.js:786:23)
at async _REST.request (C:\Users\x\Documents\Clanware\clanware-bot\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async ButtonInteraction.update (C:\Users\x\Documents\Clanware\clanware-bot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:233:5)
at async safelyReplyToInteraction (file:///C:/Users/x/Documents/Clanware/clanware-bot/node_modules/@sapphire/discord.js-utilities/dist/index.mjs:664:7)
at async _PaginatedMessage.handleCollect (file:///C:/Users/x/Documents/Clanware/clanware-bot/node_modules/@sapphire/discord.js-utilities/dist/index.mjs:1667:11) {
...
C:\Users\x\Documents\Clanware\clanware-bot\node_modules\@discordjs\rest\dist\index.js:687
throw new DiscordAPIError(data, "code" in data ? data.code : data.error, status, method, url, requestData);
^

DiscordAPIError[40060]: Interaction has already been acknowledged.
at handleErrors (C:\Users\x\Documents\Clanware\clanware-bot\node_modules\@discordjs\rest\dist\index.js:687:13)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async BurstHandler.runRequest (C:\Users\x\Documents\Clanware\clanware-bot\node_modules\@discordjs\rest\dist\index.js:786:23)
at async _REST.request (C:\Users\x\Documents\Clanware\clanware-bot\node_modules\@discordjs\rest\dist\index.js:1218:22)
at async ButtonInteraction.update (C:\Users\x\Documents\Clanware\clanware-bot\node_modules\discord.js\src\structures\interfaces\InteractionResponses.js:233:5)
at async safelyReplyToInteraction (file:///C:/Users/x/Documents/Clanware/clanware-bot/node_modules/@sapphire/discord.js-utilities/dist/index.mjs:664:7)
at async _PaginatedMessage.handleCollect (file:///C:/Users/x/Documents/Clanware/clanware-bot/node_modules/@sapphire/discord.js-utilities/dist/index.mjs:1667:11) {
...
Solution:
I found that it works when I set the customid of the button to @sapphire/paginated-messages.stop, but really it should be able to support any customid
Jump to solution
7 Replies
disclosuure
disclosuure9mo ago
@Helpers When I just run context.collector.stop(); it says Unknown Interaction
Solution
disclosuure
disclosuure9mo ago
I found that it works when I set the customid of the button to @sapphire/paginated-messages.stop, but really it should be able to support any customid
Favna
Favna9mo ago
You're overcomplicating because you're forgetting the basic JS principles of class extension and object oriented programming though. Just extend the PaginatedMessage class and override the handleEnd method. Call super.handleEnd(...args) then add your single line CaseCommand.createCaseEmbed(cases[this.index], interaction, collection); below it https://github.com/sapphiredev/utilities/blob/main/packages/discord.js-utilities/src/lib/PaginatedMessages/PaginatedMessage.ts#L1354 cases[this.index] replaces cases[context.handler.index as per https://github.com/sapphiredev/utilities/blob/main/packages/discord.js-utilities/src/lib/PaginatedMessages/PaginatedMessage.ts#L1316 adding to that, the extended class really comes down to just 8 lines of code:
import { PaginatedMessage } from '@sapphire/discord.js-utilities';

class CustomPaginatedMessage extends PaginatedMessage {
protected override async handleEnd(...args: Parameters<PaginatedMessage['handleEnd']>): Promise<void> {
await super.handleEnd(...args);
CaseCommand.createCaseEmbed(cases[this.index], interaction, collection);
}
}
import { PaginatedMessage } from '@sapphire/discord.js-utilities';

class CustomPaginatedMessage extends PaginatedMessage {
protected override async handleEnd(...args: Parameters<PaginatedMessage['handleEnd']>): Promise<void> {
await super.handleEnd(...args);
CaseCommand.createCaseEmbed(cases[this.index], interaction, collection);
}
}
Favna
Favna9mo ago
More addition, you can also add your own custom ID to stopPaginatedMessageCustomIds using PaginatedMessage.setStopPaginatedMessageCustomIds. Then your initial code would work just fine. That said, with your initial code you would have 2 stop buttons so you probably want to use the solution above instead. @cosigyn
Sapphire Framework
Class: PaginatedMessage | Sapphire
@sapphire/discord.js-utilities.PaginatedMessage
Favna
Favna9mo ago
Also if you use PaginatedMessage.setActions then you don't need include ...PaginatedMessage.defaultActions by instead setting the second parameter to true
Sapphire Framework
Class: PaginatedMessage | Sapphire
@sapphire/discord.js-utilities.PaginatedMessage
disclosuure
disclosuure9mo ago
Thank you, although I had omitted the stop button and page selector from default actions, so it would only be one button I looked through the docs but it’s quite difficult to find these different methods
Favna
Favna9mo ago
How so? I can imagine 2 factors: 1. Finding the class itself 2. The class having a lot of methods To cover 1, our website has an Algolia powered search. Either press Control (or Command) + K or click the search bar top right. (no different from the DiscordJS site for that matter if you're used to it) (also very similar to many many other technical documentation websites). As for 2... yeah that's a thing but that's just a matter of scrolling through the methods. Nothing that can be done there.