i-Moony / djs-button-pages

Simple yet powerful and extensible module to create fully-customizable embed pages with buttons.
https://i-moony.github.io/djs-button-pages/
Apache License 2.0
5 stars 0 forks source link

Interaction has already been acknowledged #3

Closed 1Psychedelic closed 1 year ago

1Psychedelic commented 1 year ago

Hello,

thanks for sharing your module!

Unfortunately I ran into a problem that I don't know how to solve. The embed message displays without a problem, it even changes the page after clicking the button, but unfortunately only once. After that it prints an error "Interaction has already been acknowledged."

More precisely:

DiscordAPIError[40060]: Interaction has already been acknowledged.
    at SequentialHandler.runRequest (.../node_modules/@discordjs/rest/dist/index.js:667:15)
    at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
    at async SequentialHandler.queueRequest (.../node_modules/@discordjs/rest/dist/index.js:464:14)
    at async REST.request (.../node_modules/@discordjs/rest/dist/index.js:910:22)
    at async ButtonInteraction.reply (.../node_modules/discord.js/src/structures/interfaces/InteractionResponses.js:111:5)
    at async Object.execute (.../messages/defaultButtonError.js:15:3)
    at async Object.execute (.../events/buttonInteraction.js:35:4)
    at async Client.<anonymous> (.../bot.js:70:23)
----------------------------------------------------------------------------------------
 rawError: 
 message: 'Interaction has already been acknowledged.',
  code: 40060
  status: 400,
  method: 'POST',
  url: 'https://discord.com/api/v10/interactions/...'
}

Code:

const prefix = process.env.prefix
const { EmbedBuilder, ButtonStyle } = require('discord.js')
const {
  ChannelPagination,
  NextPageButton,
  PreviousPageButton
} = require('djs-button-pages')

const JSONdb = require('simple-json-db')
const myDB = new JSONdb('../../db/server.json')

module.exports = {
  name: 'help',
  description: 'List all commands of bot or info about a specific command.',
  aliases: ['commands, příkazy, cmd, cmds'],
  usage: '[command name]',
  category: 'general',
  cooldown: 5,

  async execute (message, args, interaction) {
    const embeds = [
      new EmbedBuilder().setDescription('1'),
      new EmbedBuilder().setDescription('2'),
      new EmbedBuilder().setDescription('3'),
      new EmbedBuilder().setDescription('4'),
      new EmbedBuilder().setDescription('5'),
      new EmbedBuilder().setDescription('6'),
      new EmbedBuilder().setDescription('7'),
      new EmbedBuilder().setDescription('8')
    ]
    const buttons = [
      new PreviousPageButton({
        custom_id: 'prev_page',
        label: 'Previous',
        style: ButtonStyle.Success
      }),
      new NextPageButton().setStyle({
        custom_id: 'next_page',
        label: 'Next',
        style: ButtonStyle.Success
      })
    ]

    const pagination = new ChannelPagination()
      .setButtons(buttons)
      .setEmbeds(embeds)
      .setTime(60000)

    await pagination.send(message.channel)
  }
}

Can someone please advise me?

i-Moony commented 1 year ago

Sorry for delayed response.

The stack trace shows that bot.js causes the error. May I see it?

i-Moony commented 1 year ago

I am closing this issue because this is outdated.