Skip to content

Add embed character count to message builder and embeds.#1031

Closed
loukylor wants to merge 7 commits into
DSharpPlus:masterfrom
loukylor:master
Closed

Add embed character count to message builder and embeds.#1031
loukylor wants to merge 7 commits into
DSharpPlus:masterfrom
loukylor:master

Conversation

@loukylor

@loukylor loukylor commented Aug 7, 2021

Copy link
Copy Markdown

Summary

Adds a check so that the 6000 character limit on embeds is easier to track.

Details

Right now, there's no easy way to check if you've exceeded the 6000 character limit on message embeds. This should hopefully fix that issue.

Changes proposed

  • Adds a CharCount property to DiscordEmbed, DiscordEmbedField, DiscordEmbedFooter, DiscordEmbedAuthor, DiscordEmbedBuilder, EmbedAuthor, and EmbedFooter.
  • It also adds an EmbedsCharCount property to DiscordMessageBuilder.
  • A check to make sure the count does not exceed 6000 is in place for DiscordEmbedBuilder's and DiscordMessageBuilder's property. If the number is exceeded, an ArgumentException will throw.
  • The properties only reflect the characters that Discord counts.

@CabbageAdi

Copy link
Copy Markdown
Contributor

I'm not convinced this is particularly useful. You can easily just add up the characters of every field yourself.

@VelvetToroyashi

Copy link
Copy Markdown
Member

I feel quite the contrary; I'd like to have more concise error messages other than Bad Request: 400 and having to bloat my code with Chris everywhere. This is especially useful when dealing with multiple embeds, since discord doesn't explicitly state that the TOTAL character count for ALL embeds must be <= 6000 characters

@uwx

uwx commented Aug 10, 2021

Copy link
Copy Markdown
Contributor

Who the fuck is Chris

@VelvetToroyashi

Copy link
Copy Markdown
Member

LMAO checks* thanks autocorrect

@loukylor

Copy link
Copy Markdown
Author

I'm not convinced this is particularly useful. You can easily just add up the characters of every field yourself.

I do agree that it isn't too difficult to add up the characters yourself, but it sort of leaves the dev thinking: "Why isn't this just built in to the lib?". There's really no reason to not add it as I see it at least. (Given my code actually works, there might be a bug or 2 left to squash)

@DWaffles

Copy link
Copy Markdown
Contributor

I do agree that it isn't too difficult to add up the characters yourself, but it sort of leaves the dev thinking: "Why isn't this just built in to the lib?". There's really no reason to not add it as I see it at least. (Given my code actually works, there might be a bug or 2 left to squash)

I'm also in favor of this. Yes, it's not difficult. But adding this extra help reduces some of the workload by having to manually do this or have an extension method.

@CabbageAdi

Copy link
Copy Markdown
Contributor

This should not be done how you're doing it. Instead of adding to the count when a property is set, you should add the counts of all the properties when the character count property is accessed. I also feel like the character counts for the individual fields are unnecessary.

@loukylor

loukylor commented Aug 17, 2021

Copy link
Copy Markdown
Author

This should not be done how you're doing it. Instead of adding to the count when a property is set, you should add the counts of all the properties when the character count property is accessed.

So if the property returns a value larger than 6000, no error should be thrown?

I also feel like the character counts for the individual fields are unnecessary.

They're only there to make adding up char count easier.

@Naamloos

Naamloos commented Sep 29, 2021

Copy link
Copy Markdown
Member

I'd argue it's not necessary to return the counts to the user as they'd essentially have to count the characters themselves. More descriptive exceptions are a nice addition though. You never really know sure where your embed faulted.

@CabbageAdi

Copy link
Copy Markdown
Contributor

As of right now, the features in this pull request are pretty useless. If you still want to work on this, then

  • Instead of large get { } blocks, the counting should be done via single line linq queries that should be fairly simple to come up with.
  • There should be exceptions thrown when a message, webhook message, or interaction response has an embed attached where one or more properties or the entire embed exceeds one of discord's limits.

Please make these changes if you're still interested in working on this pr, otherwise it can be closed.

@loukylor

Copy link
Copy Markdown
Author

I will go ahead and close it then.

@loukylor loukylor closed this Nov 13, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants