Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(Message): add 'failIfNotExists' to ClientOptions #6038

Merged
merged 4 commits into from Jul 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/client/Client.js
Expand Up @@ -508,6 +508,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))
Expand Down
2 changes: 1 addition & 1 deletion src/structures/Message.js
Expand Up @@ -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,
},
});
}
Expand Down
2 changes: 1 addition & 1 deletion src/structures/MessagePayload.js
Expand Up @@ -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.target.client.options.failIfNotExists,
};
}
}
Expand Down
2 changes: 2 additions & 0 deletions src/util/Options.js
Expand Up @@ -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
Expand Down Expand Up @@ -108,6 +109,7 @@ class Options extends null {
retryLimit: 1,
restTimeOffset: 500,
restSweepInterval: 60,
failIfNotExists: true,
presence: {},
ws: {
large_threshold: 50,
Expand Down
1 change: 1 addition & 0 deletions typings/index.d.ts
Expand Up @@ -2978,6 +2978,7 @@ export interface ClientOptions {
restGlobalRateLimit?: number;
restSweepInterval?: number;
retryLimit?: number;
failIfNotExists?: boolean;
presence?: PresenceData;
intents: BitFieldResolvable<IntentsString, number>;
ws?: WebSocketOptions;
Expand Down