From 0679b4bcd42d67468a742cef2d0051cc10d34022 Mon Sep 17 00:00:00 2001 From: Arthur Jovart Date: Sat, 28 Aug 2021 21:02:32 +0200 Subject: [PATCH] Extract populate_owners into a new coroutine. --- discord/ext/commands/bot.py | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/discord/ext/commands/bot.py b/discord/ext/commands/bot.py index b4da6100..dbb92317 100644 --- a/discord/ext/commands/bot.py +++ b/discord/ext/commands/bot.py @@ -344,14 +344,22 @@ class BotBase(GroupMixin): elif self.owner_ids: return user.id in self.owner_ids else: + # Populate the used fields, then retry the check. This is only done at-most once in the bot lifetime. + await self.populate_owners() + return await self.is_owner(user) - app = await self.application_info() # type: ignore - if app.team: - self.owner_ids = ids = {m.id for m in app.team.members} - return user.id in ids - else: - self.owner_id = owner_id = app.owner.id - return user.id == owner_id + 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`. + + .. versionadded:: 2.0 + """ + app = await self.application_info() # type: ignore + if app.team: + self.owner_ids = {m.id for m in app.team.members} + else: + self.owner_id = app.owner.id def before_invoke(self, coro: CFT) -> CFT: """A decorator that registers a coroutine as a pre-invoke hook.