Browse Source

Add helper for checking if an application has a bot

pull/10109/head
dolfies 2 years ago
parent
commit
01dfde9648
  1. 30
      discord/application.py
  2. 1
      discord/audit_logs.py
  3. 1
      discord/embeds.py
  4. 1
      discord/ext/commands/_types.py
  5. 1
      discord/ext/commands/core.py
  6. 1
      discord/permissions.py

30
discord/application.py

@ -1760,6 +1760,7 @@ class PartialApplication(Hashable):
'owner',
'team',
'_guild',
'_has_bot',
)
if TYPE_CHECKING:
@ -1823,12 +1824,9 @@ class PartialApplication(Hashable):
else None
)
self.public: bool = data.get(
'integration_public', data.get('bot_public', True)
)
self.require_code_grant: bool = data.get(
'integration_require_code_grant', data.get('bot_require_code_grant', False)
)
self.public: bool = data.get('integration_public', data.get('bot_public', True))
self.require_code_grant: bool = data.get('integration_require_code_grant', data.get('bot_require_code_grant', False))
self._has_bot: bool = 'bot_public' in data
# Hacky, but I want these to be persisted
@ -1903,6 +1901,13 @@ class PartialApplication(Hashable):
"""Optional[:class:`Guild`]: The guild linked to the application, if any and available."""
return self._state._get_guild(self.guild_id) or self._guild
def has_bot(self) -> bool:
""":class:`bool`: Whether the application has an attached bot.
.. versionadded:: 2.1
"""
return self._has_bot
async def assets(self) -> List[ApplicationAsset]:
"""|coro|
@ -2218,6 +2223,13 @@ class Application(PartialApplication):
""":class:`ApplicationDiscoveryFlags`: The directory eligibility flags for this application."""
return ApplicationDiscoveryFlags._from_value(self._discovery_eligibility_flags)
def has_bot(self) -> bool:
""":class:`bool`: Whether the application has an attached bot.
.. versionadded:: 2.1
"""
return self.bot is not None
async def edit(
self,
*,
@ -2354,7 +2366,11 @@ class Application(PartialApplication):
else:
payload['integration_require_code_grant'] = require_code_grant
if discoverable is not MISSING:
payload['discoverability_state'] = ApplicationDiscoverabilityState.discoverable.value if discoverable else ApplicationDiscoverabilityState.not_discoverable.value
payload['discoverability_state'] = (
ApplicationDiscoverabilityState.discoverable.value
if discoverable
else ApplicationDiscoverabilityState.not_discoverable.value
)
if max_participants is not MISSING:
payload['max_participants'] = max_participants
if flags is not MISSING:

1
discord/audit_logs.py

@ -228,7 +228,6 @@ def _guild_hash_transformer(path: str) -> Callable[[AuditLogEntry, Optional[str]
def _transform_automod_trigger_metadata(
entry: AuditLogEntry, data: AutoModerationTriggerMetadata
) -> Optional[AutoModTrigger]:
if isinstance(entry.target, AutoModRule):
# Trigger type cannot be changed, so type should be the same before and after updates.
# Avoids checking which keys are in data to guess trigger type

1
discord/embeds.py

@ -175,7 +175,6 @@ class Embed:
description: Optional[Any] = None,
timestamp: Optional[datetime.datetime] = None,
):
self.colour = colour if colour is not None else color
self.title: Optional[str] = title
self.type: EmbedType = type

1
discord/ext/commands/_types.py

@ -62,7 +62,6 @@ ContextT_co = TypeVar('ContextT_co', bound='Context[Any]', covariant=True)
class Check(Protocol[ContextT_co]): # type: ignore # TypeVar is expected to be invariant
predicate: Callable[[ContextT_co], Coroutine[Any, Any, bool]]
def __call__(self, coro_or_commands: T) -> T:

1
discord/ext/commands/core.py

@ -1512,7 +1512,6 @@ class GroupMixin(Generic[CogT]):
"""
def decorator(func):
kwargs.setdefault('parent', self)
result = command(name=name, cls=cls, *args, **kwargs)(func)
self.add_command(result)

1
discord/permissions.py

@ -35,6 +35,7 @@ __all__ = (
if TYPE_CHECKING:
from typing_extensions import Self
# A permission alias works like a regular flag but is marked
# So the PermissionOverwrite knows to work with it
class permission_alias(alias_flag_value):

Loading…
Cancel
Save