Skip to content

Commit

Permalink
send will throw error if channel isn't cached
Browse files Browse the repository at this point in the history
typing updated to support contextMenu commands
  • Loading branch information
imranbarbhuiya committed Dec 25, 2021
1 parent a090365 commit 2e0e163
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import {
ButtonInteraction,
CommandInteraction,
ContextMenuInteraction,
EmojiIdentifierResolvable,
GuildMember,
InteractionReplyOptions,
Expand Down Expand Up @@ -188,6 +189,7 @@ class Pagination extends MessageEmbed {
public readonly interaction:
| CommandInteraction
| MessageComponentInteraction
| ContextMenuInteraction
| Message;
/**
* pagination button infos
Expand Down Expand Up @@ -1199,7 +1201,10 @@ class Pagination extends MessageEmbed {
async reply(): Promise<Message> {
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;
Expand All @@ -1219,7 +1224,10 @@ class Pagination extends MessageEmbed {
async followUp(): Promise<Message> {
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;
Expand All @@ -1239,7 +1247,10 @@ class Pagination extends MessageEmbed {
async editReply(): Promise<Message> {
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;
Expand Down Expand Up @@ -1278,9 +1289,12 @@ class Pagination extends MessageEmbed {
*/
async send(): Promise<Message> {
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;
}
}

Expand Down

0 comments on commit 2e0e163

Please sign in to comment.