From 5be674e3e83891a1377ef1d763ff58cc93024053 Mon Sep 17 00:00:00 2001 From: Skillz4Killz <23035000+Skillz4Killz@users.noreply.github.com> Date: Mon, 8 Mar 2021 08:41:31 -0500 Subject: [PATCH] feat(types/message): add fail_if_not_exists to Reference interface (#642) * support fail replies * fmt * fix linter issue * fix condition --- src/api/handlers/channel.ts | 1 + src/api/structures/message.ts | 11 +++++++++-- src/types/channel.ts | 2 ++ src/types/message.ts | 21 +++++++++++++++++---- 4 files changed, 29 insertions(+), 6 deletions(-) diff --git a/src/api/handlers/channel.ts b/src/api/handlers/channel.ts index 5e1b772d1..8efaf18e7 100644 --- a/src/api/handlers/channel.ts +++ b/src/api/handlers/channel.ts @@ -244,6 +244,7 @@ export async function sendMessage( ? { message_reference: { message_id: content.replyMessageID, + fail_if_not_exists: content.failReplyIfNotExists === true, }, } : {}), diff --git a/src/api/structures/message.ts b/src/api/structures/message.ts index 47e828cae..629d435c4 100644 --- a/src/api/structures/message.ts +++ b/src/api/structures/message.ts @@ -2,6 +2,7 @@ import { Activity, Application, Attachment, + DiscordReferencePayload, Embed, GuildMember, MessageContent, @@ -85,11 +86,17 @@ const baseMessage: Partial = { }, reply(content) { const contentWithMention = typeof content === "string" - ? { content, mentions: { repliedUser: true }, replyMessageID: this.id } + ? { + content, + mentions: { repliedUser: true }, + replyMessageID: this.id, + failReplyIfNotExists: false, + } : { ...content, mentions: { ...(content.mentions || {}), repliedUser: true }, replyMessageID: this.id, + failReplyIfNotExists: content.failReplyIfNotExists === true, }; if (this.guildID) return sendMessage(this.channelID!, contentWithMention); @@ -216,7 +223,7 @@ export interface Message { /** Applications that sent with Rich Presence related chat embeds. */ applications?: Application; /** The reference data sent with crossposted messages */ - messageReference?: Reference; + messageReference?: DiscordReferencePayload; /** The message flags combined like permission bits describe extra features of the message */ flags?: 1 | 2 | 4 | 8 | 16; /** the stickers sent with the message (bots currently can only receive messages with stickers, not send) */ diff --git a/src/types/channel.ts b/src/types/channel.ts index 3743c2ebc..5c0716f11 100644 --- a/src/types/channel.ts +++ b/src/types/channel.ts @@ -118,6 +118,8 @@ export interface MessageContent { "payload_json"?: string; /** If you want to send a reply message, provide the original message id here */ replyMessageID?: string; + /** When sending a reply to a message that was deleted, should Discord fail and throw an error. By default we make this false to prevent your bot from crashing. */ + failReplyIfNotExists?: boolean; } export interface FileContent { diff --git a/src/types/message.ts b/src/types/message.ts index 86f0e4d63..1d9889921 100644 --- a/src/types/message.ts +++ b/src/types/message.ts @@ -200,11 +200,23 @@ export interface Application { export interface Reference { /** The id of the originating message */ - "message_id"?: string; + // deno-lint-ignore camelcase + message_id?: string; /** The id of the originating message's channel */ - "channel_id": string; + // deno-lint-ignore camelcase + channel_id?: string; /** The id of the originating message's guild */ - "guild_id"?: string; + // deno-lint-ignore camelcase + guild_id?: string; + /** When sending, whether to error if the referenced message doesn't exist instead of sending as a normal (non-reply) message, default false */ + // deno-lint-ignore camelcase + fail_if_not_exists?: boolean; +} + +export interface DiscordReferencePayload extends Reference { + /** The id of the originating message's channel */ + // deno-lint-ignore camelcase + channel_id: string; } export enum MessageFlags { @@ -287,7 +299,8 @@ export interface MessageCreateOptions { /** Applications that sent with Rich Presence related chat embeds. */ applications?: Application; /** The reference data sent with crossposted messages */ - "message_reference"?: Reference; + // deno-lint-ignore camelcase + message_reference?: DiscordReferencePayload; /** The message flags combined like permission bits describe extra features of the message */ flags?: 1 | 2 | 4 | 8 | 16; /** the stickers sent with the message (bots currently can only receive messages with stickers, not send) */