Add try_user, owner and owners to Client #7

Merged
paris-ci merged 7 commits from try_user into 2.0 2021-09-02 19:24:52 +00:00
Showing only changes of commit f552b77c59 - Show all commits

View File

@@ -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`.
SylteA commented 2021-08-29 21:44:34 +00:00 (Migrated from github.com)
Review

If owners have not been loaded this will return None

If owners have not been loaded this will return `None`
.. versionadded:: 2.0
"""