2
2
from enum import IntEnum
3
3
from typing import Any , Callable , List , Optional , Union
4
4
5
+ from ..error import LibraryException
5
6
from .attrs_utils import (
6
7
MISSING ,
7
8
ClientSerializerMixin ,
@@ -210,7 +211,7 @@ async def send(
210
211
:rtype: Message
211
212
"""
212
213
if not self ._client :
213
- raise AttributeError ( "HTTPClient not found!" )
214
+ raise LibraryException ( code = 13 )
214
215
from ...client .models .component import _build_components
215
216
from .message import Message
216
217
@@ -264,7 +265,7 @@ async def delete(self) -> None:
264
265
Deletes the channel.
265
266
"""
266
267
if not self ._client :
267
- raise AttributeError ( "HTTPClient not found!" )
268
+ raise LibraryException ( code = 13 )
268
269
await self ._client .delete_channel (channel_id = int (self .id ))
269
270
270
271
async def modify (
@@ -319,7 +320,7 @@ async def modify(
319
320
:rtype: Channel
320
321
"""
321
322
if not self ._client :
322
- raise AttributeError ( "HTTPClient not found!" )
323
+ raise LibraryException ( code = 13 )
323
324
_name = self .name if name is MISSING else name
324
325
_topic = self .topic if topic is MISSING else topic
325
326
_bitrate = self .bitrate if bitrate is MISSING else bitrate
@@ -359,7 +360,7 @@ async def modify(
359
360
if (
360
361
archived is not MISSING or auto_archive_duration is not MISSING or locked is not MISSING
361
362
) 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 )
363
364
364
365
if archived is not MISSING :
365
366
payload ["archived" ] = archived
@@ -434,7 +435,7 @@ async def set_bitrate(
434
435
"""
435
436
436
437
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 )
438
439
439
440
return await self .modify (bitrate = bitrate , reason = reason )
440
441
@@ -456,7 +457,9 @@ async def set_user_limit(
456
457
"""
457
458
458
459
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
+ )
460
463
461
464
return await self .modify (user_limit = user_limit , reason = reason )
462
465
@@ -604,11 +607,9 @@ async def add_member(
604
607
:type member_id: int
605
608
"""
606
609
if not self ._client :
607
- raise AttributeError ( "HTTPClient not found!" )
610
+ raise LibraryException ( code = 13 )
608
611
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 )
612
613
613
614
_member_id = (
614
615
int (member_id ) if isinstance (member_id , (int , Snowflake )) else int (member_id .id )
@@ -627,7 +628,7 @@ async def pin_message(
627
628
:type message_id: Union[int, Snowflake, "Message"]
628
629
"""
629
630
if not self ._client :
630
- raise AttributeError ( "HTTPClient not found!" )
631
+ raise LibraryException ( code = 13 )
631
632
632
633
_message_id = (
633
634
int (message_id ) if isinstance (message_id , (int , Snowflake )) else int (message_id .id )
@@ -646,7 +647,7 @@ async def unpin_message(
646
647
:type message_id: Union[int, Snowflake, "Message"]
647
648
"""
648
649
if not self ._client :
649
- raise AttributeError ( "HTTPClient not found!" )
650
+ raise LibraryException ( code = 13 )
650
651
651
652
_message_id = (
652
653
int (message_id ) if isinstance (message_id , (int , Snowflake )) else int (message_id .id )
@@ -666,7 +667,7 @@ async def publish_message(
666
667
:rtype: Message
667
668
"""
668
669
if not self ._client :
669
- raise AttributeError ( "HTTPClient not found!" )
670
+ raise LibraryException ( code = 13 )
670
671
from .message import Message
671
672
672
673
_message_id = (
@@ -685,7 +686,7 @@ async def get_pinned_messages(self) -> List["Message"]: # noqa
685
686
:rtype: List[Message]
686
687
"""
687
688
if not self ._client :
688
- raise AttributeError ( "HTTPClient not found!" )
689
+ raise LibraryException ( code = 13 )
689
690
from .message import Message
690
691
691
692
res = await self ._client .get_pinned_messages (int (self .id ))
@@ -744,7 +745,7 @@ def check_pinned(message):
744
745
:rtype: List[Message]
745
746
"""
746
747
if not self ._client :
747
- raise AttributeError ( "HTTPClient not found!" )
748
+ raise LibraryException ( code = 13 )
748
749
from .message import Message
749
750
750
751
_before = None if before is MISSING else before
@@ -942,13 +943,13 @@ async def create_thread(
942
943
:rtype: Channel
943
944
"""
944
945
if not self ._client :
945
- raise AttributeError ( "HTTPClient not found!" )
946
+ raise LibraryException ( code = 13 )
946
947
if type not in [
947
948
ChannelType .GUILD_NEWS_THREAD ,
948
949
ChannelType .GUILD_PUBLIC_THREAD ,
949
950
ChannelType .GUILD_PRIVATE_THREAD ,
950
951
]:
951
- raise AttributeError ( "type must be a thread type!" )
952
+ raise LibraryException ( message = "type must be a thread type!" , code = 12 )
952
953
953
954
_auto_archive_duration = None if auto_archive_duration is MISSING else auto_archive_duration
954
955
_invitable = None if invitable is MISSING else invitable
@@ -1009,7 +1010,7 @@ async def create_invite(
1009
1010
"""
1010
1011
1011
1012
if not self ._client :
1012
- raise AttributeError ( "HTTPClient not found!" )
1013
+ raise LibraryException ( code = 13 )
1013
1014
1014
1015
payload = {
1015
1016
"max_age" : max_age ,
@@ -1021,16 +1022,17 @@ async def create_invite(
1021
1022
if (target_user_id is not MISSING and target_user_id ) and (
1022
1023
target_application_id is not MISSING and target_application_id
1023
1024
):
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
+ )
1027
1028
1028
1029
elif (
1029
1030
(target_user_id is not MISSING and target_user_id )
1030
1031
or (target_application_id is not MISSING and target_application_id )
1031
1032
) 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 ,
1034
1036
)
1035
1037
1036
1038
if target_user_id is not MISSING :
@@ -1066,7 +1068,7 @@ async def get_history(self, limit: int = 100) -> Optional[List["Message"]]: # n
1066
1068
"""
1067
1069
1068
1070
if not self ._client :
1069
- raise AttributeError ( "HTTPClient not found!" )
1071
+ raise LibraryException ( code = 13 )
1070
1072
1071
1073
from .message import Message
1072
1074
@@ -1115,7 +1117,7 @@ async def get_webhooks(self) -> List[Webhook]:
1115
1117
"""
1116
1118
1117
1119
if not self ._client :
1118
- raise AttributeError ( "HTTPClient not found!" )
1120
+ raise LibraryException ( code = 13 )
1119
1121
1120
1122
res = await self ._client .get_channel_webhooks (int (self .id ))
1121
1123
return [Webhook (** _ , _client = self ._client ) for _ in res ]
0 commit comments