feat(types/message): add fail_if_not_exists to Reference interface (#642)

* support fail replies

* fmt

* fix linter issue

* fix condition
This commit is contained in:
Skillz4Killz
2021-03-08 08:41:31 -05:00
committed by GitHub
parent 53bd6c2386
commit 5be674e3e8
4 changed files with 29 additions and 6 deletions
+1
View File
@@ -244,6 +244,7 @@ export async function sendMessage(
? { ? {
message_reference: { message_reference: {
message_id: content.replyMessageID, message_id: content.replyMessageID,
fail_if_not_exists: content.failReplyIfNotExists === true,
}, },
} }
: {}), : {}),
+9 -2
View File
@@ -2,6 +2,7 @@ import {
Activity, Activity,
Application, Application,
Attachment, Attachment,
DiscordReferencePayload,
Embed, Embed,
GuildMember, GuildMember,
MessageContent, MessageContent,
@@ -85,11 +86,17 @@ const baseMessage: Partial<Message> = {
}, },
reply(content) { reply(content) {
const contentWithMention = typeof content === "string" const contentWithMention = typeof content === "string"
? { content, mentions: { repliedUser: true }, replyMessageID: this.id } ? {
content,
mentions: { repliedUser: true },
replyMessageID: this.id,
failReplyIfNotExists: false,
}
: { : {
...content, ...content,
mentions: { ...(content.mentions || {}), repliedUser: true }, mentions: { ...(content.mentions || {}), repliedUser: true },
replyMessageID: this.id, replyMessageID: this.id,
failReplyIfNotExists: content.failReplyIfNotExists === true,
}; };
if (this.guildID) return sendMessage(this.channelID!, contentWithMention); 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 that sent with Rich Presence related chat embeds. */
applications?: Application; applications?: Application;
/** The reference data sent with crossposted messages */ /** The reference data sent with crossposted messages */
messageReference?: Reference; messageReference?: DiscordReferencePayload;
/** The message flags combined like permission bits describe extra features of the message */ /** The message flags combined like permission bits describe extra features of the message */
flags?: 1 | 2 | 4 | 8 | 16; flags?: 1 | 2 | 4 | 8 | 16;
/** the stickers sent with the message (bots currently can only receive messages with stickers, not send) */ /** the stickers sent with the message (bots currently can only receive messages with stickers, not send) */
+2
View File
@@ -118,6 +118,8 @@ export interface MessageContent {
"payload_json"?: string; "payload_json"?: string;
/** If you want to send a reply message, provide the original message id here */ /** If you want to send a reply message, provide the original message id here */
replyMessageID?: string; 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 { export interface FileContent {
+17 -4
View File
@@ -200,11 +200,23 @@ export interface Application {
export interface Reference { export interface Reference {
/** The id of the originating message */ /** The id of the originating message */
"message_id"?: string; // deno-lint-ignore camelcase
message_id?: string;
/** The id of the originating message's channel */ /** 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 */ /** 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 { export enum MessageFlags {
@@ -287,7 +299,8 @@ export interface MessageCreateOptions {
/** Applications that sent with Rich Presence related chat embeds. */ /** Applications that sent with Rich Presence related chat embeds. */
applications?: Application; applications?: Application;
/** The reference data sent with crossposted messages */ /** 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 */ /** The message flags combined like permission bits describe extra features of the message */
flags?: 1 | 2 | 4 | 8 | 16; flags?: 1 | 2 | 4 | 8 | 16;
/** the stickers sent with the message (bots currently can only receive messages with stickers, not send) */ /** the stickers sent with the message (bots currently can only receive messages with stickers, not send) */