From daa79b7f97251c777fdb109c2ff57b4fa7044c5b Mon Sep 17 00:00:00 2001 From: Zack Campbell Date: Mon, 5 Dec 2016 19:33:58 -0600 Subject: [PATCH] Add more errors for RichEmbed builder char limits (#954) * Add more errors for RichEmbed builder char limits Might as well if we're erroring on number of fields when that's the one limit that doesn't actually throw a bad request. * Fix name.length check in previous commit * Update RichEmbed.js * Update number of fields error message --- src/structures/RichEmbed.js | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/src/structures/RichEmbed.js b/src/structures/RichEmbed.js index fd56eb664..7cd98b99d 100644 --- a/src/structures/RichEmbed.js +++ b/src/structures/RichEmbed.js @@ -71,6 +71,7 @@ class RichEmbed { * @returns {RichEmbed} This embed */ setTitle(title) { + if (title.length > 256) throw new RangeError('RichEmbed titles may not exceed 256 characters.'); this.title = title; return this; } @@ -81,6 +82,7 @@ class RichEmbed { * @returns {RichEmbed} This embed */ setDescription(description) { + if (description.length > 2048) throw new RangeError('RichEmbed descriptions may not exceed 2048 characters.'); this.description = description; return this; } @@ -139,7 +141,9 @@ class RichEmbed { * @returns {RichEmbed} This embed */ addField(name, value, inline = false) { - if (this.fields.length >= 25) throw new RangeError('A RichEmbed may only have a maximum of 25 fields.'); + if (this.fields.length >= 25) throw new RangeError('RichEmbeds may not exceed 25 fields.'); + if (name.length > 256) throw new RangeError('RichEmbed field names may not exceed 256 characters.'); + if (value.length > 1024) throw new RangeError('RichEmbed field values may not exceed 1024 characters.'); this.fields.push({ name, value, inline }); return this; } @@ -171,6 +175,7 @@ class RichEmbed { * @returns {RichEmbed} This embed */ setFooter(text, icon) { + if (text.length > 2048) throw new RangeError('RichEmbed footer text may not exceed 1024 characters.'); this.footer = { text, icon_url: icon }; return this; }