From f552b77c593f2906c663f116cbb9ba3230c75d28 Mon Sep 17 00:00:00 2001 From: Arthur Jovart Date: Sat, 28 Aug 2021 21:15:11 +0200 Subject: [PATCH] Add a try_owners coroutine to get a list of owners of the bot. --- discord/ext/commands/bot.py | 36 +++++++++++++++++++++++++++++++++++- 1 file changed, 35 insertions(+), 1 deletion(-) diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index dbb92317..93b0bc76 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -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 """