22from enum import IntEnum
33from typing import Any , Callable , List , Optional , Union
44
5+ from ..error import LibraryException
56from .attrs_utils import (
67 MISSING ,
78 ClientSerializerMixin ,
@@ -210,7 +211,7 @@ async def send(
210211 :rtype: Message
211212 """
212213 if not self ._client :
213- raise AttributeError ( "HTTPClient not found!" )
214+ raise LibraryException ( code = 13 )
214215 from ...client .models .component import _build_components
215216 from .message import Message
216217
@@ -264,7 +265,7 @@ async def delete(self) -> None:
264265 Deletes the channel.
265266 """
266267 if not self ._client :
267- raise AttributeError ( "HTTPClient not found!" )
268+ raise LibraryException ( code = 13 )
268269 await self ._client .delete_channel (channel_id = int (self .id ))
269270
270271 async def modify (
@@ -319,7 +320,7 @@ async def modify(
319320 :rtype: Channel
320321 """
321322 if not self ._client :
322- raise AttributeError ( "HTTPClient not found!" )
323+ raise LibraryException ( code = 13 )
323324 _name = self .name if name is MISSING else name
324325 _topic = self .topic if topic is MISSING else topic
325326 _bitrate = self .bitrate if bitrate is MISSING else bitrate
@@ -359,7 +360,7 @@ async def modify(
359360 if (
360361 archived is not MISSING or auto_archive_duration is not MISSING or locked is not MISSING
361362 ) and not self .thread_metadata :
362- raise ValueError ( "The specified channel is not a Thread!" )
363+ raise LibraryException ( message = "The specified channel is not a Thread!" , code = 12 )
363364
364365 if archived is not MISSING :
365366 payload ["archived" ] = archived
@@ -434,7 +435,7 @@ async def set_bitrate(
434435 """
435436
436437 if self .type != ChannelType .GUILD_VOICE :
437- raise TypeError ( "Bitrate is only available for VoiceChannels" )
438+ raise LibraryException ( message = "Bitrate is only available for VoiceChannels" , code = 12 )
438439
439440 return await self .modify (bitrate = bitrate , reason = reason )
440441
@@ -456,7 +457,9 @@ async def set_user_limit(
456457 """
457458
458459 if self .type != ChannelType .GUILD_VOICE :
459- raise TypeError ("user_limit is only available for VoiceChannels" )
460+ raise LibraryException (
461+ message = "user_limit is only available for VoiceChannels" , code = 12
462+ )
460463
461464 return await self .modify (user_limit = user_limit , reason = reason )
462465
@@ -604,11 +607,9 @@ async def add_member(
604607 :type member_id: int
605608 """
606609 if not self ._client :
607- raise AttributeError ( "HTTPClient not found!" )
610+ raise LibraryException ( code = 13 )
608611 if not self .thread_metadata :
609- raise TypeError (
610- "The Channel you specified is not a thread!"
611- ) # TODO: Move to new error formatter.
612+ raise LibraryException (message = "The Channel you specified is not a thread!" , code = 12 )
612613
613614 _member_id = (
614615 int (member_id ) if isinstance (member_id , (int , Snowflake )) else int (member_id .id )
@@ -627,7 +628,7 @@ async def pin_message(
627628 :type message_id: Union[int, Snowflake, "Message"]
628629 """
629630 if not self ._client :
630- raise AttributeError ( "HTTPClient not found!" )
631+ raise LibraryException ( code = 13 )
631632
632633 _message_id = (
633634 int (message_id ) if isinstance (message_id , (int , Snowflake )) else int (message_id .id )
@@ -646,7 +647,7 @@ async def unpin_message(
646647 :type message_id: Union[int, Snowflake, "Message"]
647648 """
648649 if not self ._client :
649- raise AttributeError ( "HTTPClient not found!" )
650+ raise LibraryException ( code = 13 )
650651
651652 _message_id = (
652653 int (message_id ) if isinstance (message_id , (int , Snowflake )) else int (message_id .id )
@@ -666,7 +667,7 @@ async def publish_message(
666667 :rtype: Message
667668 """
668669 if not self ._client :
669- raise AttributeError ( "HTTPClient not found!" )
670+ raise LibraryException ( code = 13 )
670671 from .message import Message
671672
672673 _message_id = (
@@ -685,7 +686,7 @@ async def get_pinned_messages(self) -> List["Message"]: # noqa
685686 :rtype: List[Message]
686687 """
687688 if not self ._client :
688- raise AttributeError ( "HTTPClient not found!" )
689+ raise LibraryException ( code = 13 )
689690 from .message import Message
690691
691692 res = await self ._client .get_pinned_messages (int (self .id ))
@@ -744,7 +745,7 @@ def check_pinned(message):
744745 :rtype: List[Message]
745746 """
746747 if not self ._client :
747- raise AttributeError ( "HTTPClient not found!" )
748+ raise LibraryException ( code = 13 )
748749 from .message import Message
749750
750751 _before = None if before is MISSING else before
@@ -942,13 +943,13 @@ async def create_thread(
942943 :rtype: Channel
943944 """
944945 if not self ._client :
945- raise AttributeError ( "HTTPClient not found!" )
946+ raise LibraryException ( code = 13 )
946947 if type not in [
947948 ChannelType .GUILD_NEWS_THREAD ,
948949 ChannelType .GUILD_PUBLIC_THREAD ,
949950 ChannelType .GUILD_PRIVATE_THREAD ,
950951 ]:
951- raise AttributeError ( "type must be a thread type!" )
952+ raise LibraryException ( message = "type must be a thread type!" , code = 12 )
952953
953954 _auto_archive_duration = None if auto_archive_duration is MISSING else auto_archive_duration
954955 _invitable = None if invitable is MISSING else invitable
@@ -1009,7 +1010,7 @@ async def create_invite(
10091010 """
10101011
10111012 if not self ._client :
1012- raise AttributeError ( "HTTPClient not found!" )
1013+ raise LibraryException ( code = 13 )
10131014
10141015 payload = {
10151016 "max_age" : max_age ,
@@ -1021,16 +1022,17 @@ async def create_invite(
10211022 if (target_user_id is not MISSING and target_user_id ) and (
10221023 target_application_id is not MISSING and target_application_id
10231024 ):
1024- raise ValueError (
1025- "target user id and target application are mutually exclusive!"
1026- ) # TODO: move to custom error formatter
1025+ raise LibraryException (
1026+ message = "target user id and target application are mutually exclusive!" , code = 12
1027+ )
10271028
10281029 elif (
10291030 (target_user_id is not MISSING and target_user_id )
10301031 or (target_application_id is not MISSING and target_application_id )
10311032 ) and not target_type :
1032- raise ValueError (
1033- "you have to specify a target_type if you specify target_user-/target_application_id"
1033+ raise LibraryException (
1034+ message = "you have to specify a target_type if you specify target_user-/target_application_id" ,
1035+ code = 12 ,
10341036 )
10351037
10361038 if target_user_id is not MISSING :
@@ -1066,7 +1068,7 @@ async def get_history(self, limit: int = 100) -> Optional[List["Message"]]: # n
10661068 """
10671069
10681070 if not self ._client :
1069- raise AttributeError ( "HTTPClient not found!" )
1071+ raise LibraryException ( code = 13 )
10701072
10711073 from .message import Message
10721074
@@ -1115,7 +1117,7 @@ async def get_webhooks(self) -> List[Webhook]:
11151117 """
11161118
11171119 if not self ._client :
1118- raise AttributeError ( "HTTPClient not found!" )
1120+ raise LibraryException ( code = 13 )
11191121
11201122 res = await self ._client .get_channel_webhooks (int (self .id ))
11211123 return [Webhook (** _ , _client = self ._client ) for _ in res ]
0 commit comments