From 53ae80f24ebf3e0ac2afdf3a79455682e5484258 Mon Sep 17 00:00:00 2001 From: PanSzelescik Date: Sun, 4 Jul 2021 16:22:42 +0200 Subject: [PATCH 1/3] feat(Message): add 'failIfNotExists' to ClientOptions --- src/client/Client.js | 3 +++ src/structures/Message.js | 2 +- src/structures/MessagePayload.js | 2 +- src/util/Options.js | 2 ++ typings/index.d.ts | 1 + 5 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/client/Client.js b/src/client/Client.js index 95c6f77594ed..f9a0e7aa8713 100644 --- a/src/client/Client.js +++ b/src/client/Client.js @@ -499,6 +499,9 @@ class Client extends BaseClient { if (typeof options.retryLimit !== 'number' || isNaN(options.retryLimit)) { throw new TypeError('CLIENT_INVALID_OPTION', 'retryLimit', 'a number'); } + if (typeof options.failIfNotExists !== 'boolean') { + throw new TypeError('CLIENT_INVALID_OPTION', 'failIfNotExists', 'a boolean'); + } if ( typeof options.rejectOnRateLimit !== 'undefined' && !(typeof options.rejectOnRateLimit === 'function' || Array.isArray(options.rejectOnRateLimit)) diff --git a/src/structures/Message.js b/src/structures/Message.js index dbbc6c357e20..08644d6a25c6 100644 --- a/src/structures/Message.js +++ b/src/structures/Message.js @@ -697,7 +697,7 @@ class Message extends Base { data = MessagePayload.create(this, options, { reply: { messageReference: this, - failIfNotExists: options?.failIfNotExists ?? true, + failIfNotExists: options?.failIfNotExists ?? this.client.options.failIfNotExists, }, }); } diff --git a/src/structures/MessagePayload.js b/src/structures/MessagePayload.js index d53fb4f46dd1..bbb3741f7b9b 100644 --- a/src/structures/MessagePayload.js +++ b/src/structures/MessagePayload.js @@ -178,7 +178,7 @@ class MessagePayload { if (message_id) { message_reference = { message_id, - fail_if_not_exists: this.options.reply.failIfNotExists ?? true, + fail_if_not_exists: this.options.reply.failIfNotExists ?? this.client.options.failIfNotExists, }; } } diff --git a/src/util/Options.js b/src/util/Options.js index dc8e77810d26..aba947c9d2da 100644 --- a/src/util/Options.js +++ b/src/util/Options.js @@ -62,6 +62,7 @@ * route starting with /channels, such as /channels/222197033908436994/messages) or a function returning true, a * {@link RateLimitError} will be thrown. Otherwise the request will be queued for later * @property {number} [retryLimit=1] How many times to retry on 5XX errors (Infinity for indefinite amount of retries) + * @property {boolean} [failIfNotExists=true] Default value for {@link ReplyMessageOptions#failIfNotExists} * @property {PresenceData} [presence={}] Presence data to use upon login * @property {IntentsResolvable} intents Intents to enable for this connection * @property {WebsocketOptions} [ws] Options for the WebSocket @@ -108,6 +109,7 @@ class Options extends null { retryLimit: 1, restTimeOffset: 500, restSweepInterval: 60, + failIfNotExists: true, presence: {}, ws: { large_threshold: 50, diff --git a/typings/index.d.ts b/typings/index.d.ts index 4c32b5683976..5ad3f4e3deeb 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -3153,6 +3153,7 @@ declare module 'discord.js' { restGlobalRateLimit?: number; restSweepInterval?: number; retryLimit?: number; + failIfNotExists?: boolean; presence?: PresenceData; intents: BitFieldResolvable; ws?: WebSocketOptions; From ae1e1c847593b5bda6823577d938ff2a759972c2 Mon Sep 17 00:00:00 2001 From: PanSzelescik Date: Sun, 4 Jul 2021 16:36:10 +0200 Subject: [PATCH 2/3] fix(MessagePayload): 'client' from 'target' --- src/structures/MessagePayload.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/structures/MessagePayload.js b/src/structures/MessagePayload.js index bbb3741f7b9b..19ad97bca5de 100644 --- a/src/structures/MessagePayload.js +++ b/src/structures/MessagePayload.js @@ -178,7 +178,7 @@ class MessagePayload { if (message_id) { message_reference = { message_id, - fail_if_not_exists: this.options.reply.failIfNotExists ?? this.client.options.failIfNotExists, + fail_if_not_exists: this.options.reply.failIfNotExists ?? this.target.client.options.failIfNotExists, }; } } From c7a6a39cd5875d03d1a9135c1c27cfb190d04b6b Mon Sep 17 00:00:00 2001 From: PanSzelescik Date: Mon, 5 Jul 2021 13:44:29 +0100 Subject: [PATCH 3/3] fix: add line Co-authored-by: Noel --- typings/index.d.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/typings/index.d.ts b/typings/index.d.ts index c60ce9516e44..95ce4e4b4725 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -4345,4 +4345,4 @@ export type InternalDiscordGatewayAdapterCreator = ( methods: InternalDiscordGatewayAdapterLibraryMethods, ) => InternalDiscordGatewayAdapterImplementerMethods; -//#endregion \ No newline at end of file +//#endregion