Skip to content

Commit 00526f7

Browse files
committed
Move is_owner
1 parent 849c57e commit 00526f7

File tree

1 file changed

+38
-0
lines changed

1 file changed

+38
-0
lines changed

discord/bot.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from .errors import Forbidden, DiscordException
6363
from .interactions import Interaction
6464
from .enums import InteractionType
65+
from .user import User
6566

6667
CoroFunc = Callable[..., Coroutine[Any, Any, Any]]
6768
CFT = TypeVar('CFT', bound=CoroFunc)
@@ -953,6 +954,43 @@ def after_invoke(self, coro):
953954
self._after_invoke = coro
954955
return coro
955956

957+
async def is_owner(self, user: User) -> bool:
958+
"""|coro|
959+
960+
Checks if a :class:`~discord.User` or :class:`~discord.Member` is the owner of
961+
this bot.
962+
963+
If an :attr:`owner_id` is not set, it is fetched automatically
964+
through the use of :meth:`~.Bot.application_info`.
965+
966+
.. versionchanged:: 1.3
967+
The function also checks if the application is team-owned if
968+
:attr:`owner_ids` is not set.
969+
970+
Parameters
971+
-----------
972+
user: :class:`.abc.User`
973+
The user to check for.
974+
975+
Returns
976+
--------
977+
:class:`bool`
978+
Whether the user is the owner.
979+
"""
980+
981+
if self.owner_id:
982+
return user.id == self.owner_id
983+
elif self.owner_ids:
984+
return user.id in self.owner_ids
985+
else:
986+
app = await self.application_info() # type: ignore
987+
if app.team:
988+
self.owner_ids = ids = {m.id for m in app.team.members}
989+
return user.id in ids
990+
else:
991+
self.owner_id = owner_id = app.owner.id
992+
return user.id == owner_id
993+
956994

957995
class Bot(BotBase, Client):
958996
"""Represents a discord bot.

0 commit comments

Comments
 (0)