Skip to content

Commit 1e549e8

Browse files
committed
Add is_..._integration helper methods
1 parent 1b2972b commit 1e549e8

File tree

2 files changed

+36
-0
lines changed

2 files changed

+36
-0
lines changed

discord/commands/context.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,22 @@ def cog(self) -> Cog | None:
345345

346346
return self.command.cog
347347

348+
def is_guild_integration(self) -> bool:
349+
""":class:`bool`: Returns ``True`` if the invoked command was guild installed.
350+
This is a shortcut for :meth:`Interaction.is_guild_integration`.
351+
352+
.. versionadded:: 2.7
353+
"""
354+
return self.interaction.is_guild_integration()
355+
356+
def is_user_integration(self) -> bool:
357+
""":class:`bool`: Returns ``True`` if the invoked command was user installed.
358+
This is a shortcut for :meth:`Interaction.is_user_integration`.
359+
360+
.. versionadded:: 2.7
361+
"""
362+
return self.interaction.is_user_integration()
363+
348364

349365
class AutocompleteContext:
350366
"""Represents context for a slash command's option autocomplete.

discord/interactions.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -360,6 +360,26 @@ def followup(self) -> Webhook:
360360
}
361361
return Webhook.from_state(data=payload, state=self._state)
362362

363+
def is_guild_integration(self) -> bool:
364+
""":class:`bool`: Returns ``True`` if the interaction is a guild integration.
365+
366+
.. versionadded:: 2.7
367+
"""
368+
if self.guild_id:
369+
return self.authorizing_integration_owners.guild_id == self.guild_id
370+
return False
371+
372+
def is_user_integration(self) -> bool:
373+
""":class:`bool`: Returns ``True`` if the interaction is a user integration.
374+
375+
.. versionadded:: 2.7
376+
"""
377+
if self.user:
378+
return self.authorizing_integration_owners.user_id == self.user.id
379+
380+
# This return should not be called but making sure it returns the expected value
381+
return False
382+
363383
async def original_response(self) -> InteractionMessage:
364384
"""|coro|
365385

0 commit comments

Comments
 (0)