Skip to content

Commit c60fbab

Browse files
committed
feat: update get_or_fetch method to accept Optional[int] for object_id
1 parent fb9e077 commit c60fbab

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

discord/client.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,15 @@
3131
import sys
3232
import traceback
3333
from types import TracebackType
34-
from typing import TYPE_CHECKING, Any, Callable, Coroutine, Generator, Sequence, TypeVar
34+
from typing import (
35+
TYPE_CHECKING,
36+
Any,
37+
Callable,
38+
Coroutine,
39+
Generator,
40+
Sequence,
41+
TypeVar,
42+
)
3543

3644
import aiohttp
3745

@@ -1147,7 +1155,7 @@ async def get_or_fetch_user(self, id: int, /) -> User | None: # TODO: Remove in
11471155
async def get_or_fetch(
11481156
self: Client,
11491157
object_type: type[_FETCHABLE],
1150-
object_id: int,
1158+
object_id: int | None,
11511159
default: Any = MISSING,
11521160
) -> _FETCHABLE | None:
11531161
"""

discord/guild.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ def get_member(self, user_id: int, /) -> Member | None:
867867
async def get_or_fetch(
868868
self: Guild,
869869
object_type: type[_FETCHABLE],
870-
object_id: int,
870+
object_id: int | None,
871871
default: Any = MISSING,
872872
) -> _FETCHABLE | None:
873873
"""

discord/utils.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -599,7 +599,7 @@ def get(iterable: Iterable[T], **attrs: Any) -> T | None:
599599
async def get_or_fetch(
600600
obj: Guild | Client,
601601
object_type: type[_FETCHABLE] = MISSING,
602-
object_id: int = MISSING,
602+
object_id: int | None = MISSING,
603603
default: Any = MISSING,
604604
attr: str = MISSING,
605605
id: int = MISSING,
@@ -637,6 +637,9 @@ async def get_or_fetch(
637637
"""
638638
from discord import AppEmoji, Client, Guild, Member, Role, User, abc, emoji
639639

640+
if object_id is None:
641+
return None
642+
640643
string_to_type = {
641644
"channel": abc.GuildChannel,
642645
"member": Member,

0 commit comments

Comments
 (0)