Skip to content

Commit

Permalink
Add is_..._integration helper methods
Browse files Browse the repository at this point in the history
  • Loading branch information
DA-344 committed Nov 28, 2024
1 parent 1b2972b commit 1e549e8
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
16 changes: 16 additions & 0 deletions discord/commands/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,6 +345,22 @@ def cog(self) -> Cog | None:

return self.command.cog

def is_guild_integration(self) -> bool:
""":class:`bool`: Returns ``True`` if the invoked command was guild installed.
This is a shortcut for :meth:`Interaction.is_guild_integration`.
.. versionadded:: 2.7
"""
return self.interaction.is_guild_integration()

def is_user_integration(self) -> bool:
""":class:`bool`: Returns ``True`` if the invoked command was user installed.
This is a shortcut for :meth:`Interaction.is_user_integration`.
.. versionadded:: 2.7
"""
return self.interaction.is_user_integration()


class AutocompleteContext:
"""Represents context for a slash command's option autocomplete.
Expand Down
20 changes: 20 additions & 0 deletions discord/interactions.py
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,26 @@ def followup(self) -> Webhook:
}
return Webhook.from_state(data=payload, state=self._state)

def is_guild_integration(self) -> bool:
""":class:`bool`: Returns ``True`` if the interaction is a guild integration.
.. versionadded:: 2.7
"""
if self.guild_id:
return self.authorizing_integration_owners.guild_id == self.guild_id
return False

def is_user_integration(self) -> bool:
""":class:`bool`: Returns ``True`` if the interaction is a user integration.
.. versionadded:: 2.7
"""
if self.user:
return self.authorizing_integration_owners.user_id == self.user.id

# This return should not be called but making sure it returns the expected value
return False

async def original_response(self) -> InteractionMessage:
"""|coro|
Expand Down

0 comments on commit 1e549e8

Please sign in to comment.