File tree Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Expand file tree Collapse file tree 2 files changed +12
-2
lines changed Original file line number Diff line number Diff line change 56
56
57
57
58
58
class DiscordException (Exception ):
59
- """Base exception class for pycord
59
+ """Base exception class for Pycord
60
60
61
61
Ideally speaking, this could be caught to handle any exceptions raised from this library.
62
62
"""
Original file line number Diff line number Diff line change 61
61
import types
62
62
import warnings
63
63
64
- from .errors import InvalidArgument
64
+ from .errors import InvalidArgument , NotFound
65
+ from .guild import Guild
65
66
66
67
try :
67
68
import orjson
@@ -448,6 +449,15 @@ def get(iterable: Iterable[T], **attrs: Any) -> Optional[T]:
448
449
return elem
449
450
return None
450
451
452
+ async def get_or_fetch (guild : Guild , type : str , id : int ):
453
+ getter = getattr (guild , f'get_{ type } ' )(id )
454
+ if getter is None :
455
+ try :
456
+ getter = await getattr (guild , f'fetch_{ type } ' )(id )
457
+ except NotFound :
458
+ raise NotFound (404 , 'HTTP request operation failed.' )
459
+ return getter
460
+
451
461
452
462
def _unique (iterable : Iterable [T ]) -> List [T ]:
453
463
return [x for x in dict .fromkeys (iterable )]
You can’t perform that action at this time.
0 commit comments