Add a try_owners coroutine to get a list of owners of the bot.
This commit is contained in:
@@ -348,10 +348,44 @@ class BotBase(GroupMixin):
|
|||||||
await self.populate_owners()
|
await self.populate_owners()
|
||||||
return await self.is_owner(user)
|
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):
|
async def populate_owners(self):
|
||||||
"""|coro|
|
"""|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
|
.. versionadded:: 2.0
|
||||||
"""
|
"""
|
||||||
|
Reference in New Issue
Block a user