devRael1 / discordjs-pagination

A pagination system for Discord.js v14
https://www.npmjs.com/package/@devraelfreeze/discordjs-pagination
MIT License
11 stars 10 forks source link

DeleteAtEnd is not working. #16

Open Zer0-Access opened 1 year ago

Zer0-Access commented 1 year ago

const {SlashCommandBuilder, EmbedBuilder, ButtonBuilder, ActionRowBuilder, ButtonStyle, CommandInteraction} = require('discord.js');

const {pagination, ButtonTypes, ButtonStyles} = require('@devraelfreeze/discordjs-pagination');

module.exports = { data: new SlashCommandBuilder() .setName("pagetest") .setDescription("Simple command testing pagnation."), async execute(interaction) {

    const embed1 = new EmbedBuilder()
    .setColor("LuminousVividPink")
    .setTitle(`Charlie Company Welcome Page:`)
    .setDescription(`This is page 1.`)
    .addFields({
        name: `Introduction:`,
        value: `Sample Test`,  
    }) 
    .addFields({
        name: `Rules:`,
        value: `- After 60 seconds both buttons will become disabled and you will no longer be able to use this interaction.\n- Do not go inactive on this embed unless you are done.\n- Information on this page is only strictly for Charlie Company Section Staff+ only.`,
    })
const embed2 = new EmbedBuilder()
    .setColor("LuminousVividPink")
    .setTitle(`Charlie Company HICOM:`)
    .setDescription(`This is page 2.`)
const embed3 = new EmbedBuilder()
    .setColor("LuminousVividPink")
    .setTitle(`Page 3:`)
    .setDescription(`This is page 3.`)

const restrictedEmbed = new EmbedBuilder()
.setColor("DarkRed")
.setTitle("Unauthorized Access")
.addFields({
  name: "Invalid Permissions:",
  value: "You do not have permissions to view this embed."
})
    if(interaction.member.user.id === '436673206380920844') {
      return interaction.reply({embeds: [restrictedEmbed]});
    } else {
      await pagination({
        embeds: [
            embed1,
            embed2,
            embed3
        ],
        author: interaction.member.user,
        interaction,
        ephemeral: false,
        time: 10000, 
        fastSkip: false,
        pageTravel: false,
        deleteAtEnd: true,
        buttons: [
          {
            type: ButtonTypes.previous,
            label: 'Previous Page',
            style: ButtonStyles.Primary
          },
          {
            type: ButtonTypes.next,
            label: 'Next Page',
            style: ButtonStyles.Success
          }
        ]
      });
    }
}

}

However, when the time expires the embed does not delete.

devconstantalt commented 3 months ago

Yes

collector.on("end", async () => {
    try {
        if (deleteAtEnd) {
            if (type === 'message') {
                await initialMessage.delete();
            } else {
                await interaction.deleteReply();
            }
        } else {
            // If deleteAtEnd is false, just remove the buttons
            if (type === 'message') {
                await initialMessage.edit({
                    components: disableB ? components(true) : []
                });
            } else {
                await interaction.editReply({
                    components: disableB ? components(true) : []
                });
            }
        }
    } catch (error) {
        console.error('Error deleting or editing message:', error);
    }
});

I think this will work