|
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)
|
@@ -953,6 +954,43 @@ def after_invoke(self, coro):
|
953 | 954 | self._after_invoke = coro
|
954 | 955 | return coro
|
955 | 956 |
|
| 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 | + |
956 | 994 |
|
957 | 995 | class Bot(BotBase, Client):
|
958 | 996 | """Represents a discord bot.
|
|
0 commit comments