11use std:: borrow:: Cow ;
22
33#[ cfg( feature = "http" ) ]
4- use super :: { check_overflow , Builder } ;
4+ use super :: Builder ;
55use super :: {
66 CreateActionRow ,
77 CreateAllowedMentions ,
@@ -10,8 +10,6 @@ use super::{
1010 EditAttachments ,
1111} ;
1212#[ cfg( feature = "http" ) ]
13- use crate :: constants;
14- #[ cfg( feature = "http" ) ]
1513use crate :: http:: CacheHttp ;
1614#[ cfg( feature = "http" ) ]
1715use crate :: internal:: prelude:: * ;
@@ -83,22 +81,8 @@ impl<'a> CreateMessage<'a> {
8381 }
8482
8583 #[ cfg( feature = "http" ) ]
86- fn check_length ( & self ) -> Result < ( ) > {
87- if let Some ( content) = & self . content {
88- check_overflow ( content. chars ( ) . count ( ) , constants:: MESSAGE_CODE_LIMIT )
89- . map_err ( |overflow| Error :: Model ( ModelError :: MessageTooLong ( overflow) ) ) ?;
90- }
91-
92- check_overflow ( self . embeds . len ( ) , constants:: EMBED_MAX_COUNT )
93- . map_err ( |_| Error :: Model ( ModelError :: EmbedAmount ) ) ?;
94- for embed in self . embeds . iter ( ) {
95- embed. check_length ( ) ?;
96- }
97-
98- check_overflow ( self . sticker_ids . len ( ) , constants:: STICKER_MAX_COUNT )
99- . map_err ( |_| Error :: Model ( ModelError :: StickerAmount ) ) ?;
100-
101- Ok ( ( ) )
84+ fn check_length ( & self ) -> Result < ( ) , ModelError > {
85+ super :: check_lengths ( self . content . as_deref ( ) , Some ( & self . embeds ) , self . sticker_ids . len ( ) )
10286 }
10387
10488 /// Set the content of the message.
@@ -300,7 +284,7 @@ impl Builder for CreateMessage<'_> {
300284 ///
301285 /// # Errors
302286 ///
303- /// Returns a [`ModelError::MessageTooLong `] if the message contents are over the above limits.
287+ /// Returns a [`ModelError::TooLarge `] if the message contents are over the above limits.
304288 ///
305289 /// If the `cache` is enabled, returns a [`ModelError::InvalidPermissions`] if the current user
306290 /// lacks permission. Otherwise returns [`Error::Http`], as well as if invalid data is given.
0 commit comments