Discord.js: RichEmbedBuilder constraints are too strict for emoji

Created on 28 Jan 2018  路  1Comment  路  Source: discordjs/discord.js

Embed titles, field names, field values etc. are restricted too much when containing emoji due to JavaScript's Unicode nonsense.

The following code generates an error:

message.channel.send( new Discord.RichEmbed().setTitle(`馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃馃`) )

=> RangeError: RichEmbed titles may not exceed 256 characters.

However, because Discord API doesn't consider 馃 as 2 characters, the title is still valid, since it is 256 emoji. The same embed can be sent as an object without error:

message.channel.send({ embed: { title: `馃馃馃馃馃馃...you get the point` }})

There are probably compatibility issues with doing so, but it seems to me you could replace all statements like:
if (title.length > 256) throw new RangeError('EMBED_TITLE');
with their equivalents of:
if (Array.from(title).length > 256) throw new RangeError('EMBED_TITLE');.

Further details:

  • discord.js version: 11.2.1
  • node.js version: 7.7.4
  • Operating system: Windows 10
  • Priority: low
REST bug

Most helpful comment

cc @Lewdcario we should just remove the checks on our side, they're kinda pointless since the api will catch them for us

>All comments

cc @Lewdcario we should just remove the checks on our side, they're kinda pointless since the api will catch them for us

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DatMayo picture DatMayo  路  3Comments

Dmitry221060 picture Dmitry221060  路  3Comments

Brawaru picture Brawaru  路  3Comments

shukriadams picture shukriadams  路  3Comments

tom-barnes picture tom-barnes  路  3Comments