|
62 | 62 | from .errors import Forbidden, DiscordException
|
63 | 63 | from .interactions import Interaction
|
64 | 64 | from .enums import InteractionType
|
| 65 | +from .user import User |
65 | 66 |
|
66 | 67 | CoroFunc = Callable[..., Coroutine[Any, Any, Any]]
|
67 | 68 | CFT = TypeVar('CFT', bound=CoroFunc)
|
@@ -1019,6 +1020,43 @@ def after_invoke(self, coro):
|
1019 | 1020 | self._after_invoke = coro
|
1020 | 1021 | return coro
|
1021 | 1022 |
|
| 1023 | + async def is_owner(self, user: User) -> bool: |
| 1024 | + """|coro| |
| 1025 | +
|
| 1026 | + Checks if a :class:`~discord.User` or :class:`~discord.Member` is the owner of |
| 1027 | + this bot. |
| 1028 | +
|
| 1029 | + If an :attr:`owner_id` is not set, it is fetched automatically |
| 1030 | + through the use of :meth:`~.Bot.application_info`. |
| 1031 | +
|
| 1032 | + .. versionchanged:: 1.3 |
| 1033 | + The function also checks if the application is team-owned if |
| 1034 | + :attr:`owner_ids` is not set. |
| 1035 | +
|
| 1036 | + Parameters |
| 1037 | + ----------- |
| 1038 | + user: :class:`.abc.User` |
| 1039 | + The user to check for. |
| 1040 | +
|
| 1041 | + Returns |
| 1042 | + -------- |
| 1043 | + :class:`bool` |
| 1044 | + Whether the user is the owner. |
| 1045 | + """ |
| 1046 | + |
| 1047 | + if self.owner_id: |
| 1048 | + return user.id == self.owner_id |
| 1049 | + elif self.owner_ids: |
| 1050 | + return user.id in self.owner_ids |
| 1051 | + else: |
| 1052 | + app = await self.application_info() # type: ignore |
| 1053 | + if app.team: |
| 1054 | + self.owner_ids = ids = {m.id for m in app.team.members} |
| 1055 | + return user.id in ids |
| 1056 | + else: |
| 1057 | + self.owner_id = owner_id = app.owner.id |
| 1058 | + return user.id == owner_id |
| 1059 | + |
1022 | 1060 |
|
1023 | 1061 | class Bot(BotBase, Client):
|
1024 | 1062 | """Represents a discord bot.
|
|
0 commit comments