diff --git a/.github/workflows/npm-publish.yml b/.github/workflows/npm-publish.yml new file mode 100644 index 0000000..6cdebaf --- /dev/null +++ b/.github/workflows/npm-publish.yml @@ -0,0 +1,33 @@ +# This workflow will run tests using node and then publish a package to GitHub Packages when a release is created +# For more information see: https://docs.github.com/en/actions/publishing-packages/publishing-nodejs-packages + +name: Node.js Package + +on: + release: + types: [created] + +jobs: + build: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + - run: npm ci + - run: npm test + + publish-npm: + needs: build + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + - uses: actions/setup-node@v3 + with: + node-version: 16 + registry-url: https://registry.npmjs.org/ + - run: npm ci + - run: npm publish + env: + NODE_AUTH_TOKEN: ${{secrets.npm_token}} diff --git a/README.md b/README.md index c62accf..244aaf3 100644 --- a/README.md +++ b/README.md @@ -2,29 +2,21 @@
-# discordjs-button-pagination +# discordjs-button-pagination-v2 A simple package to paginate discord embeds via discord buttons introduced in [discord.js v13](https://github.com/discordjs/discord.js/tree/master). # Versions -## `discordjs-button-pagination@interaction` [Default] +## `discordjs-button-pagination-v2@interaction` [Default] for slash command interaction. -## `discordjs-button-pagination@msg` -for message command. # Installation -For `message` event -* `npm install discordjs-button-pagination@msg` -For `interaction` event -* `npm install discordjs-button-pagination@interaction` - -## Default command: `npm install discordjs-button-pagination` will install the **`interaction`** version +### Default command: `npm install discordjs-button-pagination-v2` # Requirements Node.js 16.6.1 or newer is required along with Discord.js 13.0.0 or newer. @@ -34,28 +26,28 @@ Node.js 16.6.1 or newer is required along with Discord.js 13.0.0 or newer. __Basic Bot Example__ ```js // Import the discordjs-button-pagination package -const paginationEmbed = require('discordjs-button-pagination'); +const paginationEmbed = require('discordjs-button-pagination-v2'); // Use MessageEmbed to make pages // Keep in mind that Embeds should't have their footers set since the pagination method sets page info there -const { MessageEmbed , MessageButton} = require('discord.js'); -const embed1 = new MessageEmbed() +const { EmbedBuilder , ButtonBuilder, ButtonStyle} = require('discord.js'); +const embed1 = new EmbedBuilder() .setTitle('First Page') .setDescription('This is the first page'); -const embed2 = new MessageEmbed() +const embed2 = new EmbedBuilder() .setTitle('Second Page') .setDescription('This is the second page'); -const button1 = new MessageButton() +const button1 = new ButtonBuilder() .setCustomId('previousbtn') .setLabel('Previous') - .setStyle('DANGER'); + .setStyle(ButtonStyle.Danger); -const button2 = new MessageButton() +const button2 = new ButtonBuilder() .setCustomId('nextbtn') .setLabel('Next') - .setStyle('SUCCESS'); + .setStyle(ButtonStyle.Success); // Create an array of embeds pages = [ @@ -81,6 +73,7 @@ paginationEmbed(interaction, pages, buttonList, timeout); # Note This will not work with buttons whose style is set as 'LINK' as they do not trigger an interaction event. The buttons will auto disable once the the collector ends after the timeout. +You must use the following custom ids for it to work. "previousbtn" and "nextbtn" ## The collector timer resets after receiving a button interaction. # Preview @@ -103,5 +96,5 @@ Disabled Buttons after collector end -### For any issues or suggestions, kindly open an issue/pull request on the [**GitHub Repository**](https://github.com/ryzyx/discordjs-button-pagination) +### For any issues or suggestions, kindly open an issue/pull request on the [**GitHub Repository**](https://github.com/chillingcone426/discordjs-button-pagination) diff --git a/index.js b/index.js index f9fb6e8..96ebc42 100644 --- a/index.js +++ b/index.js @@ -1,15 +1,10 @@ -const { - MessageActionRow, - Message, - MessageEmbed, - MessageButton, -} = require("discord.js"); +const { ActionRowBuilder, ButtonBuilder, ButtonStyle, EmbedBuilder, ComponentType } = require('discord.js'); /** * Creates a pagination embed * @param {Interaction} interaction - * @param {MessageEmbed[]} pages - * @param {MessageButton[]} buttonList + * @param {EmbedBuilder[]} pages + * @param {ButtonBuilder[]} buttonList * @param {number} timeout * @returns */ @@ -29,7 +24,7 @@ const paginationEmbed = async ( let page = 0; - const row = new MessageActionRow().addComponents(buttonList); + const row = new ActionRowBuilder().addComponents(buttonList); //has the interaction already been deferred? If not, defer the reply. if (interaction.deferred == false) { @@ -42,21 +37,22 @@ const paginationEmbed = async ( fetchReply: true, }); - const filter = (i) => + const filter = (i) => { + i.deferUpdate(); i.customId === buttonList[0].customId || i.customId === buttonList[1].customId; - + }; const collector = await curPage.createMessageComponentCollector({ - filter, time: timeout, + componentType: ComponentType.Button, }); collector.on("collect", async (i) => { switch (i.customId) { - case buttonList[0].customId: + case "previousbtn": page = page > 0 ? --page : pages.length - 1; break; - case buttonList[1].customId: + case "nextbtn": page = page + 1 < pages.length ? ++page : 0; break; default: @@ -72,7 +68,7 @@ const paginationEmbed = async ( collector.on("end", (_, reason) => { if (reason !== "messageDelete") { - const disabledRow = new MessageActionRow().addComponents( + const disabledRow = new ActionRowBuilder().addComponents( buttonList[0].setDisabled(true), buttonList[1].setDisabled(true) ); diff --git a/package.json b/package.json index b05a526..cde6588 100644 --- a/package.json +++ b/package.json @@ -1,14 +1,14 @@ { - "name": "discordjs-button-pagination", - "version": "3.0.1", - "description": "A simple package for pagination using buttons introduced in discord.js v13.", + "name": "discordjs-button-pagination-v2", + "version": "4.0.2", + "description": "A simple package for pagination using buttons introduced in discord.js v13 that was updates to work with discord.js v14.", "main": "index.js", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", - "url": "git+https://github.com/ryzyx/discordjs-button-pagination.git" + "url": "git+https://github.com/chillingcone426/discordjs-button-pagination.git" }, "keywords": [ "Discord", @@ -19,13 +19,13 @@ "discordjs", "discord.js" ], - "author": "Ryzyx", + "author": "thebeston123", "license": "MIT", "bugs": { - "url": "https://github.com/ryzyx/discordjs-button-pagination/issues" + "url": "https://github.com/chillingcone426/discordjs-button-pagination/issues" }, - "homepage": "https://github.com/ryzyx/discordjs-button-pagination#readme", + "homepage": "https://github.com/chillingcone426/discordjs-button-pagination#readme", "dependencies": { - "discord.js": "^13.0.1" + "discord.js": "^14.11.0" } }