Skip to content

Commit 52f9c98

Browse files
authored
Merge pull request #594 from Pycord-Development/fix-duplicates
Fix duplicates
2 parents 58cad18 + 3db4e11 commit 52f9c98

File tree

3 files changed

+41
-559
lines changed

3 files changed

+41
-559
lines changed

discord/bot.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
from .errors import Forbidden, DiscordException
6363
from .interactions import Interaction
6464
from .enums import InteractionType
65+
from .user import User
6566

6667
CoroFunc = Callable[..., Coroutine[Any, Any, Any]]
6768
CFT = TypeVar('CFT', bound=CoroFunc)
@@ -1019,6 +1020,43 @@ def after_invoke(self, coro):
10191020
self._after_invoke = coro
10201021
return coro
10211022

1023+
async def is_owner(self, user: User) -> bool:
1024+
"""|coro|
1025+
1026+
Checks if a :class:`~discord.User` or :class:`~discord.Member` is the owner of
1027+
this bot.
1028+
1029+
If an :attr:`owner_id` is not set, it is fetched automatically
1030+
through the use of :meth:`~.Bot.application_info`.
1031+
1032+
.. versionchanged:: 1.3
1033+
The function also checks if the application is team-owned if
1034+
:attr:`owner_ids` is not set.
1035+
1036+
Parameters
1037+
-----------
1038+
user: :class:`.abc.User`
1039+
The user to check for.
1040+
1041+
Returns
1042+
--------
1043+
:class:`bool`
1044+
Whether the user is the owner.
1045+
"""
1046+
1047+
if self.owner_id:
1048+
return user.id == self.owner_id
1049+
elif self.owner_ids:
1050+
return user.id in self.owner_ids
1051+
else:
1052+
app = await self.application_info() # type: ignore
1053+
if app.team:
1054+
self.owner_ids = ids = {m.id for m in app.team.members}
1055+
return user.id in ids
1056+
else:
1057+
self.owner_id = owner_id = app.owner.id
1058+
return user.id == owner_id
1059+
10221060

10231061
class Bot(BotBase, Client):
10241062
"""Represents a discord bot.

discord/cog.py

Lines changed: 2 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
__all__ = (
4242
'CogMeta',
4343
'Cog',
44-
'CogMixin'
44+
'CogMixin',
4545
)
4646

4747
CogT = TypeVar('CogT', bound='Cog')
@@ -254,16 +254,7 @@ def get_commands(self) -> List[ApplicationCommand]:
254254
255255
This does not include subcommands.
256256
"""
257-
return [
258-
c for c in (
259-
c for c in self.__cog_commands__
260-
if not isinstance(c, (SlashCommand, MessageCommand, UserCommand))
261-
) if c.parent is None
262-
] + [
263-
c for c in self.__cog_commands__
264-
if isinstance(c, (SlashCommand, MessageCommand, UserCommand))
265-
]
266-
257+
return [c for c in self.__cog_commands__ if isinstance(c, ApplicationCommand) and c.parent is None]
267258
@property
268259
def qualified_name(self) -> str:
269260
""":class:`str`: Returns the cog's specified name, not the class name."""

0 commit comments

Comments
 (0)