I need a way to get the exact length of a embed so i can check if it goes over the limit. So if it does go over the limit, it can split into multiple messages/embeds.
I need a way to get the exact length of a embed so i can check if it goes over the limit. So if it does go over the limit, it can split into multiple messages/embeds.
If we take a look at the official Discord documentation for rich Embed limits we can see that the total limit is 6000 characters.
Additionally, the characters in all
title,description,field.name,field.value,footer.text, andauthor.namefields must not exceed 6000 characters in total. Violating any of these constraints will result in aBad Requestresponse.
But there are also individual limits as follows:
+-------------+------------------------+
| Field | Limit |
+-------------+------------------------+
| title | 256 characters |
| description | 4096 characters* |
| fields | Up to 25 field objects |
| field.name | 256 characters |
| field.value | 1024 characters |
| footer.text | 2048 characters |
| author.name | 256 characters |
+-------------+------------------------+
*see this announcement in the Discord Developers server
So in many cases you may need to check and handle all of these limits individually. In the end, here is how to check if the total embed limit has been hit, this does not check the individual limits above.
# embed would be the discord.Embed instance
fields = [embed.title, embed.description, embed.footer.text, embed.author.name]
fields.extend([field.name for field in embed.fields])
fields.extend([field.value for field in embed.fields])
total = ""
for item in fields:
# If we str(discord.Embed.Empty) we get 'Embed.Empty', when
# we just want an empty string...
total += str(item) if str(item) != 'Embed.Empty' else ''
print(len(total))