From 2e0e1635154fecdfa55c43514b31d5ea1594245a Mon Sep 17 00:00:00 2001 From: Parbez <74945038+imranbarbhuiya@users.noreply.github.com> Date: Sat, 25 Dec 2021 10:10:59 +0530 Subject: [PATCH] send will throw error if channel isn't cached typing updated to support contextMenu commands --- src/index.ts | 26 ++++++++++++++++++++------ 1 file changed, 20 insertions(+), 6 deletions(-) diff --git a/src/index.ts b/src/index.ts index 111fe36..7fe8257 100644 --- a/src/index.ts +++ b/src/index.ts @@ -1,6 +1,7 @@ import { ButtonInteraction, CommandInteraction, + ContextMenuInteraction, EmojiIdentifierResolvable, GuildMember, InteractionReplyOptions, @@ -188,6 +189,7 @@ class Pagination extends MessageEmbed { public readonly interaction: | CommandInteraction | MessageComponentInteraction + | ContextMenuInteraction | Message; /** * pagination button infos @@ -1199,7 +1201,10 @@ class Pagination extends MessageEmbed { async reply(): Promise { const payloads = this.ready(); const message = await ( - this.interaction as CommandInteraction | MessageComponentInteraction + this.interaction as + | CommandInteraction + | MessageComponentInteraction + | ContextMenuInteraction ).reply(payloads); this.paginate(message as Message); return message as Message; @@ -1219,7 +1224,10 @@ class Pagination extends MessageEmbed { async followUp(): Promise { const payloads = this.ready(); const message = await ( - this.interaction as CommandInteraction | MessageComponentInteraction + this.interaction as + | CommandInteraction + | MessageComponentInteraction + | ContextMenuInteraction ).followUp(payloads); this.paginate(message as Message); return message as Message; @@ -1239,7 +1247,10 @@ class Pagination extends MessageEmbed { async editReply(): Promise { const payloads = this.ready(); const message = await ( - this.interaction as CommandInteraction | MessageComponentInteraction + this.interaction as + | CommandInteraction + | MessageComponentInteraction + | ContextMenuInteraction ).editReply(payloads); this.paginate(message as Message); return message as Message; @@ -1278,9 +1289,12 @@ class Pagination extends MessageEmbed { */ async send(): Promise { const payloads = this.ready(); - const message = await this.interaction.channel?.send(payloads); - this.paginate(message as Message); - return message as Message; + const message = (await this.interaction.channel?.send(payloads)) ?? null; + if (message) this.paginate(message); + else { + throw new Error("Channel is not cached"); + } + return message; } }