From c21f25a981fdcea3357c37e48393fa4f70aa41db Mon Sep 17 00:00:00 2001
From: Egor
builder.setDefaultButtons(['first', {
- 'stop': new MessageButton()
- .setLabel('Stop')
- .setStyle('PRIMARY')
+ stop: new MessageButton()
+ .setLabel('Stop')
+ .setStyle('PRIMARY')
}]);
import { PagesBuilder } from 'discord.js-pages';
+ import { PagesBuilder, PagesManager } from 'discord.js-pages';
import { Client, MessageEmbed } from 'discord.js';
const client = new Client({
@@ -2759,6 +2759,8 @@ Usage 📦
]
});
+const pagesManager = new PagesManager();
+
// Middleware is useful in bots with modular commands
client.on('interactionCreate', (interaction) => {
pagesManager.middleware(interaction);
diff --git a/docs/modules.html b/docs/modules.html
index 4e8a8af..1307759 100644
--- a/docs/modules.html
+++ b/docs/modules.html
@@ -2738,7 +2738,7 @@
📖 Documentation
- 🤖 Examples
+ 🤖 Examples
@@ -2750,7 +2750,7 @@ Install 📦
Usage 📦
- import { PagesBuilder } from 'discord.js-pages';
+ import { PagesBuilder, PagesManager } from 'discord.js-pages';
import { Client, MessageEmbed } from 'discord.js';
const client = new Client({
@@ -2759,6 +2759,8 @@ Usage 📦
]
});
+const pagesManager = new PagesManager();
+
// Middleware is useful in bots with modular commands
client.on('interactionCreate', (interaction) => {
pagesManager.middleware(interaction);
diff --git a/examples/buttons/customButtons.js b/examples/buttons/customButtons.js
new file mode 100644
index 0000000..ad17909
--- /dev/null
+++ b/examples/buttons/customButtons.js
@@ -0,0 +1,64 @@
+import { Client, MessageEmbed, MessageButton, MessageActionRow } from 'discord.js';
+import { PagesBuilder } from 'discord.js-pages';
+
+const client = new Client({
+ intents: [
+ 'GUILDS'
+ ]
+});
+
+client.on('interactionCreate', (interaction) => {
+ // Custom buttons & select
+ new PagesBuilder(interaction)
+ .setTitle('Global title')
+ .setPages([
+ new MessageEmbed()
+ .setDescription('First page'),
+ new MessageEmbed()
+ .setDescription('Second page')
+ ])
+ .setComponents([
+ new MessageActionRow()
+ .setComponents(
+ new MessageButton()
+ .setCustomId('custom')
+ .setLabel('Custom button')
+ .setStyle('PRIMARY')
+ )
+ ])
+ // You can add buttons/selects to the end of the list.
+ // The library itself will find the component in which there is a place or create new for the element and add it.
+ // Support array.
+ .addComponents(
+ new MessageButton()
+ .setCustomId('awesome')
+ .setLabel('Awesome button')
+ .setStyle('SECONDARY')
+ )
+ // Add triggers for handling interactions with buttons/selects.
+ // Support array.
+ .setTriggers({
+ name: 'custom',
+ callback(interactionCallback, button) {
+ button.setDisabled(true);
+
+ interaction.followUp({
+ content: 'Custom button callback!'
+ });
+ }
+ })
+ .addTriggers({
+ name: 'awesome',
+ callback(interactionCallback, button) {
+ button.setDisabled(true)
+ .setLabel('¯\\_(ツ)_/¯');
+
+ interaction.followUp({
+ content: 'Awesome button callback!'
+ });
+ }
+ })
+ .build();
+});
+
+client.login(process.env.TOKEN);
\ No newline at end of file
diff --git a/examples/buttons/dynamicUpdate.js b/examples/buttons/dynamicUpdate.js
new file mode 100644
index 0000000..ef312c0
--- /dev/null
+++ b/examples/buttons/dynamicUpdate.js
@@ -0,0 +1,45 @@
+import { Client, MessageEmbed, MessageButton, MessageActionRow } from 'discord.js';
+import { PagesBuilder } from 'discord.js-pages';
+
+const client = new Client({
+ intents: [
+ 'GUILDS'
+ ]
+});
+
+client.on('interactionCreate', (interaction) => {
+ const link = new MessageButton()
+ .setLabel('Dynamic link')
+ .setStyle('LINK');
+
+ // Dynamic buttons update
+ const builder = new PagesBuilder(interaction)
+ .setTitle('Global title');
+
+ builder.setPages([
+ () => {
+ link.setURL('https://google.com/');
+
+ builder.setComponents(
+ new MessageActionRow()
+ .addComponents(link)
+ );
+
+ return new MessageEmbed()
+ .setDescription('First page');
+ },
+ () => {
+ link.setURL('https://discord.com/');
+
+ builder.setComponents(
+ new MessageActionRow()
+ .addComponents(link)
+ );
+
+ return new MessageEmbed()
+ .setDescription('Second page');
+ }
+ ]);
+});
+
+client.login(process.env.TOKEN);
\ No newline at end of file
diff --git a/examples/buttons/quickActions.js b/examples/buttons/quickActions.js
new file mode 100644
index 0000000..c7695c0
--- /dev/null
+++ b/examples/buttons/quickActions.js
@@ -0,0 +1,30 @@
+import { Client, MessageEmbed, MessageButton } from 'discord.js';
+import { PagesBuilder } from 'discord.js-pages';
+
+const client = new Client({
+ intents: [
+ 'GUILDS'
+ ]
+});
+
+client.on('interactionCreate', (interaction) => {
+ // Quick actions
+ new PagesBuilder(interaction)
+ .setTitle('Global title')
+ .setPages([
+ new MessageEmbed()
+ .setDescription('First page'),
+ new MessageEmbed()
+ .setDescription('Second page')
+ ])
+ // Add buttons with quick pagination actions, also you can customize it.
+ // There is no need to set customId, the library does it for you.
+ .setDefaultButtons(['first', {
+ stop: new MessageButton()
+ .setLabel('Stop')
+ .setStyle('PRIMARY')
+ }])
+ .build();
+});
+
+client.login(process.env.TOKEN);
\ No newline at end of file
diff --git a/examples/files.js b/examples/files.js
new file mode 100644
index 0000000..3c2e284
--- /dev/null
+++ b/examples/files.js
@@ -0,0 +1,30 @@
+import { Client, MessageAttachment, MessageEmbed } from 'discord.js';
+import { PagesBuilder } from 'discord.js-pages';
+
+const client = new Client({
+ intents: [
+ 'GUILDS'
+ ]
+});
+
+client.on('interactionCreate', (interaction) => {
+ // To start using the files, you must add them to PagesBuilder, after adding you can use them on each page.
+ new PagesBuilder(interaction)
+ .setPages([
+ new MessageEmbed()
+ .setDescription('First page')
+ .setThumbnail('attachment://discord.png'),
+ new MessageEmbed()
+ .setDescription('Second page')
+ ])
+ // Supports array.
+ .setFiles(
+ new MessageAttachment(
+ Buffer.from('data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAANUAAADwCAYAAACXISEGAAAACXBIWXMAACE4AAAhOAFFljFgAAAAAXNSR0IArs4c6QAAAARnQU1BAACxjwv8YQUAAA6sSURBVHgB7d3xfdRGFsDxZz73P3AFHCINBK6Ai7gCLiQFXJYUcEAKONYpIEADsbkCLtAAXhoIpoGgNBBMA6eb53nC8rLe1e6OpJnR7/v5DLvYZs1KenpvRrMjEQAAA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/KLH+1nubA4hArG+lc/hin+qmJ3+dWvRD6JNq8MU0l/pbWp/GnLkOBUFZP+RHiVe73/RtklWK9rdc+821/9Vx+U3Qm9rv85jo8fe69vM681DHF1yFoDdu+5Z1HPILpmV1HMF1JOidHcxjyT+YltX+TPa6Hj64NKALQe90O7v2Rz2s6QXTstoH11E9XHB9JxiM296P6mHo8fNzPeVgWlb7s9pR3W9p+FowOLfdf637oceJZsJ57YfysYpunLq/flchGJzb7nfqsJoS72FNMG2nvlwa7htgc8Foap9N9tFkpac1Jd7+al8a7pO9uCY1stpXILtcuyIr9a32pcTRFgGmZ7dCMDrbd132WbuvVAqGU1+Uh3+s2VmPBNGorx4NpLyLjdsR91cEGBd5I1RfXBQmkFJhAfaUsi9Ote8jE0gAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAADI1/8BF5/tuAkCIRIAAAAASUVORK5CYII=', 'base64'),
+ 'discord.png'
+ )
+ )
+ .build();
+});
+
+client.login(process.env.TOKEN);
\ No newline at end of file
diff --git a/examples/initialization.js b/examples/initialization.js
new file mode 100644
index 0000000..a08e83c
--- /dev/null
+++ b/examples/initialization.js
@@ -0,0 +1,44 @@
+import { Client, MessageEmbed } from 'discord.js';
+import { PagesBuilder, PagesManager } from 'discord.js-pages';
+
+const client = new Client({
+ intents: [
+ 'GUILDS'
+ ]
+});
+
+const pagesManager = new PagesManager();
+
+// Middleware is useful in bots with modular commands
+client.on('interactionCreate', (interaction) => {
+ pagesManager.middleware(interaction);
+
+ interaction.pagesBuilder()
+ .setTitle('Global title')
+ .setPages([
+ new MessageEmbed()
+ .setDescription('First page'),
+ new MessageEmbed()
+ .setDescription('Second page')
+ ])
+ .addField('Global field', 'discord.js-pages', true)
+ .setColor('GREEN')
+ .build();
+});
+
+// Also you can create PagesBuilder instance directly
+client.on('interactionCreate', (interaction) => {
+ new PagesBuilder(interaction)
+ .setTitle('Global title')
+ .setPages([
+ new MessageEmbed()
+ .setDescription('First page'),
+ new MessageEmbed()
+ .setDescription('Second page')
+ ])
+ .addField('Global field', 'discord.js-pages', true)
+ .setColor('GREEN')
+ .build();
+});
+
+client.login(process.env.TOKEN);
\ No newline at end of file
diff --git a/examples/rootEmbed.js b/examples/rootEmbed.js
new file mode 100644
index 0000000..3160484
--- /dev/null
+++ b/examples/rootEmbed.js
@@ -0,0 +1,30 @@
+import { Client, MessageEmbed } from 'discord.js';
+import { PagesBuilder } from 'discord.js-pages';
+
+const client = new Client({
+ intents: [
+ 'GUILDS'
+ ]
+});
+
+client.on('interactionCreate', (interaction) => {
+ // PagesBuilder extends the MessageEmbed class, it inherits all of its methods and properties.
+ // You can add new properties using methods.
+ //
+ // When you add properties in this way,
+ // they will be prioritized and will replace/supplement the properties of the child MessageEmbed
+ // that are set via the setPages/addPages method.
+ new PagesBuilder(interaction)
+ .setTitle('Global title')
+ .setPages([
+ new MessageEmbed()
+ .setDescription('First page'),
+ new MessageEmbed()
+ .setDescription('Second page')
+ ])
+ .addField('Global field', 'discord.js-pages', true)
+ .setColor('GREEN')
+ .build();
+});
+
+client.login(process.env.TOKEN);
\ No newline at end of file
diff --git a/src/PagesBuilder.ts b/src/PagesBuilder.ts
index ebd76f8..9a2d112 100644
--- a/src/PagesBuilder.ts
+++ b/src/PagesBuilder.ts
@@ -278,9 +278,9 @@ export class PagesBuilder extends MessageEmbed {
* @example
* ```
* builder.setDefaultButtons(['first', {
- * 'stop': new MessageButton()
- * .setLabel('Stop')
- * .setStyle('PRIMARY')
+ * stop: new MessageButton()
+ * .setLabel('Stop')
+ * .setStyle('PRIMARY')
* }]);
* ```
*/