Skip to content

Commit c21f25a

Browse files
committed
chore(docs): examples
1 parent 3cf4246 commit c21f25a

File tree

12 files changed

+263
-13
lines changed

12 files changed

+263
-13
lines changed

.npmignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
/src
55
/build
66
/scripts
7+
/examples
78
.eslintrc.json
89
.gitignore
910
tsconfig.json

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,8 @@
99
<img src="https://badge.fury.io/js/discord.js-pages.svg" alt="npm version" height="18">
1010
</a>
1111

12-
| 📖 [Documentation](https://mrzillagold.github.io/discord.js-pages/index.html) |
13-
| ---------------------------------------------------------------------------- |
12+
| 📖 [Documentation](https://mrzillagold.github.io/discord.js-pages/index.html) | [🤖 Examples](https://github.com/MrZillaGold/discord.js-pages) |
13+
| --- | --- |
1414

1515
</p>
1616

@@ -19,7 +19,7 @@
1919

2020
### Usage 📦
2121
```js
22-
import { PagesBuilder } from 'discord.js-pages';
22+
import { PagesBuilder, PagesManager } from 'discord.js-pages';
2323
import { Client, MessageEmbed } from 'discord.js';
2424

2525
const client = new Client({
@@ -28,6 +28,8 @@ const client = new Client({
2828
]
2929
});
3030

31+
const pagesManager = new PagesManager();
32+
3133
// Middleware is useful in bots with modular commands
3234
client.on('interactionCreate', (interaction) => {
3335
pagesManager.middleware(interaction);

docs/classes/PagesBuilder.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3978,9 +3978,9 @@ <h3>set<wbr>Default<wbr>Buttons</h3>
39783978
<dl class="tsd-comment-tags">
39793979
<dt>example</dt>
39803980
<dd><pre><code><span style="color: #001080">builder</span><span style="color: #000000">.</span><span style="color: #795E26">setDefaultButtons</span><span style="color: #000000">([</span><span style="color: #A31515">&#039;first&#039;</span><span style="color: #000000">, {</span>
3981-
<span style="color: #000000"> </span><span style="color: #A31515">&#039;stop&#039;</span><span style="color: #001080">:</span><span style="color: #000000"> </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">MessageButton</span><span style="color: #000000">()</span>
3982-
<span style="color: #000000"> .</span><span style="color: #795E26">setLabel</span><span style="color: #000000">(</span><span style="color: #A31515">&#039;Stop&#039;</span><span style="color: #000000">)</span>
3983-
<span style="color: #000000"> .</span><span style="color: #795E26">setStyle</span><span style="color: #000000">(</span><span style="color: #A31515">&#039;PRIMARY&#039;</span><span style="color: #000000">)</span>
3981+
<span style="color: #000000"> </span><span style="color: #001080">stop:</span><span style="color: #000000"> </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">MessageButton</span><span style="color: #000000">()</span>
3982+
<span style="color: #000000"> .</span><span style="color: #795E26">setLabel</span><span style="color: #000000">(</span><span style="color: #A31515">&#039;Stop&#039;</span><span style="color: #000000">)</span>
3983+
<span style="color: #000000"> .</span><span style="color: #795E26">setStyle</span><span style="color: #000000">(</span><span style="color: #A31515">&#039;PRIMARY&#039;</span><span style="color: #000000">)</span>
39843984
<span style="color: #000000">}]);</span>
39853985
</code></pre>
39863986
</dd>

docs/index.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,7 @@ <h1 align="center">
27382738
<thead>
27392739
<tr>
27402740
<th>📖 <a href="https://mrzillagold.github.io/discord.js-pages/index.html">Documentation</a></th>
2741-
<th>🤖 <a href="docs/examples">Examples</a></th>
2741+
<th><a href="https://github.com/MrZillaGold/discord.js-pages">🤖 Examples</a></th>
27422742
</tr>
27432743
</thead>
27442744
</table>
@@ -2750,7 +2750,7 @@ <h3>Install 📦</h3>
27502750
<a href="#usage-📦" id="usage-📦" style="color: inherit; text-decoration: none;">
27512751
<h3>Usage 📦</h3>
27522752
</a>
2753-
<pre><code class="language-js"><span style="color: #AF00DB">import</span><span style="color: #000000"> { </span><span style="color: #001080">PagesBuilder</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;discord.js-pages&#039;</span><span style="color: #000000">;</span>
2753+
<pre><code class="language-js"><span style="color: #AF00DB">import</span><span style="color: #000000"> { </span><span style="color: #001080">PagesBuilder</span><span style="color: #000000">, </span><span style="color: #001080">PagesManager</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;discord.js-pages&#039;</span><span style="color: #000000">;</span>
27542754
<span style="color: #AF00DB">import</span><span style="color: #000000"> { </span><span style="color: #001080">Client</span><span style="color: #000000">, </span><span style="color: #001080">MessageEmbed</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;discord.js&#039;</span><span style="color: #000000">;</span>
27552755

27562756
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">client</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">Client</span><span style="color: #000000">({</span>
@@ -2759,6 +2759,8 @@ <h3>Usage 📦</h3>
27592759
<span style="color: #000000"> ]</span>
27602760
<span style="color: #000000">});</span>
27612761

2762+
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">pagesManager</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">PagesManager</span><span style="color: #000000">();</span>
2763+
27622764
<span style="color: #008000">// Middleware is useful in bots with modular commands</span>
27632765
<span style="color: #001080">client</span><span style="color: #000000">.</span><span style="color: #795E26">on</span><span style="color: #000000">(</span><span style="color: #A31515">&#039;interactionCreate&#039;</span><span style="color: #000000">, (</span><span style="color: #001080">interaction</span><span style="color: #000000">) </span><span style="color: #0000FF">=&gt;</span><span style="color: #000000"> {</span>
27642766
<span style="color: #000000"> </span><span style="color: #001080">pagesManager</span><span style="color: #000000">.</span><span style="color: #795E26">middleware</span><span style="color: #000000">(</span><span style="color: #001080">interaction</span><span style="color: #000000">);</span>

docs/modules.html

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2738,7 +2738,7 @@ <h1 align="center">
27382738
<thead>
27392739
<tr>
27402740
<th>📖 <a href="https://mrzillagold.github.io/discord.js-pages/index.html">Documentation</a></th>
2741-
<th>🤖 <a href="docs/examples">Examples</a></th>
2741+
<th><a href="https://github.com/MrZillaGold/discord.js-pages">🤖 Examples</a></th>
27422742
</tr>
27432743
</thead>
27442744
</table>
@@ -2750,7 +2750,7 @@ <h3>Install 📦</h3>
27502750
<a href="#usage-📦" id="usage-📦" style="color: inherit; text-decoration: none;">
27512751
<h3>Usage 📦</h3>
27522752
</a>
2753-
<pre><code class="language-js"><span style="color: #AF00DB">import</span><span style="color: #000000"> { </span><span style="color: #001080">PagesBuilder</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;discord.js-pages&#039;</span><span style="color: #000000">;</span>
2753+
<pre><code class="language-js"><span style="color: #AF00DB">import</span><span style="color: #000000"> { </span><span style="color: #001080">PagesBuilder</span><span style="color: #000000">, </span><span style="color: #001080">PagesManager</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;discord.js-pages&#039;</span><span style="color: #000000">;</span>
27542754
<span style="color: #AF00DB">import</span><span style="color: #000000"> { </span><span style="color: #001080">Client</span><span style="color: #000000">, </span><span style="color: #001080">MessageEmbed</span><span style="color: #000000"> } </span><span style="color: #AF00DB">from</span><span style="color: #000000"> </span><span style="color: #A31515">&#039;discord.js&#039;</span><span style="color: #000000">;</span>
27552755

27562756
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">client</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">Client</span><span style="color: #000000">({</span>
@@ -2759,6 +2759,8 @@ <h3>Usage 📦</h3>
27592759
<span style="color: #000000"> ]</span>
27602760
<span style="color: #000000">});</span>
27612761

2762+
<span style="color: #0000FF">const</span><span style="color: #000000"> </span><span style="color: #0070C1">pagesManager</span><span style="color: #000000"> = </span><span style="color: #0000FF">new</span><span style="color: #000000"> </span><span style="color: #795E26">PagesManager</span><span style="color: #000000">();</span>
2763+
27622764
<span style="color: #008000">// Middleware is useful in bots with modular commands</span>
27632765
<span style="color: #001080">client</span><span style="color: #000000">.</span><span style="color: #795E26">on</span><span style="color: #000000">(</span><span style="color: #A31515">&#039;interactionCreate&#039;</span><span style="color: #000000">, (</span><span style="color: #001080">interaction</span><span style="color: #000000">) </span><span style="color: #0000FF">=&gt;</span><span style="color: #000000"> {</span>
27642766
<span style="color: #000000"> </span><span style="color: #001080">pagesManager</span><span style="color: #000000">.</span><span style="color: #795E26">middleware</span><span style="color: #000000">(</span><span style="color: #001080">interaction</span><span style="color: #000000">);</span>

examples/buttons/customButtons.js

Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
import { Client, MessageEmbed, MessageButton, MessageActionRow } from 'discord.js';
2+
import { PagesBuilder } from 'discord.js-pages';
3+
4+
const client = new Client({
5+
intents: [
6+
'GUILDS'
7+
]
8+
});
9+
10+
client.on('interactionCreate', (interaction) => {
11+
// Custom buttons & select
12+
new PagesBuilder(interaction)
13+
.setTitle('Global title')
14+
.setPages([
15+
new MessageEmbed()
16+
.setDescription('First page'),
17+
new MessageEmbed()
18+
.setDescription('Second page')
19+
])
20+
.setComponents([
21+
new MessageActionRow()
22+
.setComponents(
23+
new MessageButton()
24+
.setCustomId('custom')
25+
.setLabel('Custom button')
26+
.setStyle('PRIMARY')
27+
)
28+
])
29+
// You can add buttons/selects to the end of the list.
30+
// The library itself will find the component in which there is a place or create new for the element and add it.
31+
// Support array.
32+
.addComponents(
33+
new MessageButton()
34+
.setCustomId('awesome')
35+
.setLabel('Awesome button')
36+
.setStyle('SECONDARY')
37+
)
38+
// Add triggers for handling interactions with buttons/selects.
39+
// Support array.
40+
.setTriggers({
41+
name: 'custom',
42+
callback(interactionCallback, button) {
43+
button.setDisabled(true);
44+
45+
interaction.followUp({
46+
content: 'Custom button callback!'
47+
});
48+
}
49+
})
50+
.addTriggers({
51+
name: 'awesome',
52+
callback(interactionCallback, button) {
53+
button.setDisabled(true)
54+
.setLabel('¯\\_(ツ)_/¯');
55+
56+
interaction.followUp({
57+
content: 'Awesome button callback!'
58+
});
59+
}
60+
})
61+
.build();
62+
});
63+
64+
client.login(process.env.TOKEN);

examples/buttons/dynamicUpdate.js

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
import { Client, MessageEmbed, MessageButton, MessageActionRow } from 'discord.js';
2+
import { PagesBuilder } from 'discord.js-pages';
3+
4+
const client = new Client({
5+
intents: [
6+
'GUILDS'
7+
]
8+
});
9+
10+
client.on('interactionCreate', (interaction) => {
11+
const link = new MessageButton()
12+
.setLabel('Dynamic link')
13+
.setStyle('LINK');
14+
15+
// Dynamic buttons update
16+
const builder = new PagesBuilder(interaction)
17+
.setTitle('Global title');
18+
19+
builder.setPages([
20+
() => {
21+
link.setURL('https://google.com/');
22+
23+
builder.setComponents(
24+
new MessageActionRow()
25+
.addComponents(link)
26+
);
27+
28+
return new MessageEmbed()
29+
.setDescription('First page');
30+
},
31+
() => {
32+
link.setURL('https://discord.com/');
33+
34+
builder.setComponents(
35+
new MessageActionRow()
36+
.addComponents(link)
37+
);
38+
39+
return new MessageEmbed()
40+
.setDescription('Second page');
41+
}
42+
]);
43+
});
44+
45+
client.login(process.env.TOKEN);

examples/buttons/quickActions.js

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import { Client, MessageEmbed, MessageButton } from 'discord.js';
2+
import { PagesBuilder } from 'discord.js-pages';
3+
4+
const client = new Client({
5+
intents: [
6+
'GUILDS'
7+
]
8+
});
9+
10+
client.on('interactionCreate', (interaction) => {
11+
// Quick actions
12+
new PagesBuilder(interaction)
13+
.setTitle('Global title')
14+
.setPages([
15+
new MessageEmbed()
16+
.setDescription('First page'),
17+
new MessageEmbed()
18+
.setDescription('Second page')
19+
])
20+
// Add buttons with quick pagination actions, also you can customize it.
21+
// There is no need to set customId, the library does it for you.
22+
.setDefaultButtons(['first', {
23+
stop: new MessageButton()
24+
.setLabel('Stop')
25+
.setStyle('PRIMARY')
26+
}])
27+
.build();
28+
});
29+
30+
client.login(process.env.TOKEN);

examples/files.js

Lines changed: 30 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)