Skip to content

Commit 846abf9

Browse files
committed
chore(builder): ephemeral support
1 parent ab54ac6 commit 846abf9

File tree

3 files changed

+25
-11
lines changed

3 files changed

+25
-11
lines changed

package-lock.json

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

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "discord.js-pages",
3-
"version": "1.4.1",
3+
"version": "1.4.2",
44
"description": "Dynamic pages pagination module for discord.js",
55
"scripts": {
66
"build": "tsc && babel build --out-dir lib --copy-files",

src/builder.ts

Lines changed: 22 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ import {
1414
SelectMenuComponent,
1515
InteractionCollector,
1616
SelectMenuInteraction,
17+
InteractionReplyOptions,
1718
WebhookEditMessageOptions,
1819
MessageComponentInteraction,
1920
ChatInputCommandInteraction,
@@ -239,7 +240,7 @@ export class PagesBuilder extends EmbedBuilder {
239240

240241
resultPage.setFooter({
241242
...resultPage.data.footer,
242-
text: pageNumber
243+
text: `${pageNumber}${pageNumber ? ' • ' : ''}${resultPage.data.footer?.text}`
243244
});
244245
}
245246

@@ -541,7 +542,7 @@ export class PagesBuilder extends EmbedBuilder {
541542
/**
542543
* Build method
543544
*/
544-
async build(): Promise<void | Message | APIMessage> {
545+
async build(options: Pick<InteractionReplyOptions, 'ephemeral'> = {}): Promise<void | Message | APIMessage> {
545546
if (this.pages.length === 0) {
546547
throw new TypeError('Pages not set');
547548
}
@@ -560,7 +561,8 @@ export class PagesBuilder extends EmbedBuilder {
560561
components: this.simplifyKeyboard([
561562
...this.defaultButtons,
562563
...this.components
563-
])
564+
]),
565+
...options
564566
})
565567
.then((message) => {
566568
if (message) {
@@ -674,7 +676,19 @@ export class PagesBuilder extends EmbedBuilder {
674676
this.handleSelectMenuComponent(event);
675677
}
676678
})
677-
.on('end', async () => {
679+
.on('end', async (collection) => {
680+
const messageComponentId = this.messageComponent?.id;
681+
682+
if (!messageComponentId) {
683+
return;
684+
}
685+
686+
const interaction = collection.get(messageComponentId);
687+
688+
if (!interaction) {
689+
return;
690+
}
691+
678692
switch (this.endMethod) {
679693
case EndMethod.EDIT: {
680694
const embeds = await this.getPage();
@@ -683,27 +697,27 @@ export class PagesBuilder extends EmbedBuilder {
683697

684698
embed.setColor(this.endColor);
685699

686-
this.message.edit({
700+
interaction.editReply({
687701
embeds,
688702
components: []
689703
})
690704
.catch(() => null);
691705
break;
692706
}
693707
case EndMethod.REMOVE_COMPONENTS:
694-
this.message.edit({
708+
interaction.editReply({
695709
components: []
696710
})
697711
.catch(() => null);
698712
break;
699713
case EndMethod.REMOVE_EMBEDS:
700-
this.message.edit({
714+
interaction.editReply({
701715
embeds: []
702716
})
703717
.catch(() => null);
704718
break;
705719
case EndMethod.DELETE:
706-
this.message.delete()
720+
interaction.deleteReply()
707721
.catch(() => null);
708722
break;
709723
}

0 commit comments

Comments
 (0)