From 4b555fdf4c3b35fa0ea284f9cd56765ecb608b89 Mon Sep 17 00:00:00 2001 From: Junseo Park Date: Mon, 23 Nov 2020 03:13:38 +0900 Subject: [PATCH] feat(Message): added string type for message nonce (#4782) Co-authored-by: Vlad Frangu Co-authored-by: Sugden <28943913+NotSugden@users.noreply.github.com> Co-authored-by: SpaceEEC --- src/errors/Messages.js | 2 +- src/structures/APIMessage.js | 7 +++++-- typings/index.d.ts | 4 ++-- 3 files changed, 8 insertions(+), 5 deletions(-) diff --git a/src/errors/Messages.js b/src/errors/Messages.js index a68cd2da2..4149ef151 100644 --- a/src/errors/Messages.js +++ b/src/errors/Messages.js @@ -71,7 +71,7 @@ const Messages = { IMAGE_SIZE: size => `Invalid image size: ${size}`, MESSAGE_BULK_DELETE_TYPE: 'The messages must be an Array, Collection, or number.', - MESSAGE_NONCE_TYPE: 'Message nonce must fit in an unsigned 64-bit integer.', + MESSAGE_NONCE_TYPE: 'Message nonce must be an integer or a string.', TYPING_COUNT: 'Count must be at least 1', diff --git a/src/structures/APIMessage.js b/src/structures/APIMessage.js index 3451bdb9b..5f6aea9ca 100644 --- a/src/structures/APIMessage.js +++ b/src/structures/APIMessage.js @@ -151,8 +151,11 @@ class APIMessage { let nonce; if (typeof this.options.nonce !== 'undefined') { - nonce = parseInt(this.options.nonce); - if (isNaN(nonce) || nonce < 0) throw new RangeError('MESSAGE_NONCE_TYPE'); + nonce = this.options.nonce; + // eslint-disable-next-line max-len + if (typeof nonce === 'number' ? !Number.isInteger(nonce) : typeof nonce !== 'string') { + throw new RangeError('MESSAGE_NONCE_TYPE'); + } } const embedLikes = []; diff --git a/typings/index.d.ts b/typings/index.d.ts index e0be3c612..24a0d7d7a 100644 --- a/typings/index.d.ts +++ b/typings/index.d.ts @@ -976,7 +976,7 @@ declare module 'discord.js' { public id: Snowflake; public readonly member: GuildMember | null; public mentions: MessageMentions; - public nonce: string | null; + public nonce: string | number | null; public readonly partial: false; public readonly pinnable: boolean; public pinned: boolean; @@ -2830,7 +2830,7 @@ declare module 'discord.js' { interface MessageOptions { tts?: boolean; - nonce?: string; + nonce?: string | number; content?: StringResolvable; embed?: MessageEmbed | MessageEmbedOptions; disableMentions?: 'none' | 'all' | 'everyone';