Add try_user, owner and owners to Client #7
@@ -348,10 +348,44 @@ class BotBase(GroupMixin):
|
||||
await self.populate_owners()
|
||||
return await self.is_owner(user)
|
||||
|
||||
async def try_owners(self) -> List[discord.User]:
|
||||
"""|coro|
|
||||
|
||||
Returns a list of :class:`~discord.User` representing the owners of the bot.
|
||||
It uses the :attr:`owner_id` and :attr:`owner_ids`, if set.
|
||||
|
||||
.. versionadded:: 2.0
|
||||
The function also checks if the application is team-owned if
|
||||
:attr:`owner_ids` is not set.
|
||||
|
||||
Parameters
|
||||
-----------
|
||||
user: :class:`.abc.User`
|
||||
The user to check for.
|
||||
|
||||
Returns
|
||||
--------
|
||||
List[:class:`~discord.User`]
|
||||
List of owners of the bot.
|
||||
"""
|
||||
if self.owner_id:
|
||||
owner = await self.try_user(self.owner_id)
|
||||
if owner:
|
||||
return [owner]
|
||||
else:
|
||||
return []
|
||||
elif self.owner_ids:
|
||||
owners = []
|
||||
for owner_id in self.owner_ids:
|
||||
owner = await self.try_user(owner_id)
|
||||
if owner:
|
||||
owners.append(owner)
|
||||
return owners
|
||||
|
||||
async def populate_owners(self):
|
||||
"""|coro|
|
||||
|
||||
Populate the :meth:`.Bot.owner_id` and :meth:`.Bot.owner_ids` through the use of :meth:`~.Bot.application_info`.
|
||||
Populate the :attr:`owner_id` and :attr:`owner_ids` through the use of :meth:`~.Bot.application_info`.
|
||||
|
||||
|
||||
.. versionadded:: 2.0
|
||||
"""
|
||||
|
Reference in New Issue
Block a user
If owners have not been loaded this will return
None