Skip to content

Commit

Permalink
feat: Add client parameter for default Integration Type
Browse files Browse the repository at this point in the history
silasary committed Jan 21, 2025
1 parent 337c204 commit f34d5db
Showing 2 changed files with 11 additions and 2 deletions.
11 changes: 10 additions & 1 deletion interactions/client/client.py
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@
Awaitable,
Tuple,
TypeVar,
cast,
overload,
)

@@ -96,6 +97,7 @@
ComponentType,
Intents,
InteractionType,
IntegrationType,
Status,
MessageFlags,
)
@@ -296,6 +298,7 @@ def __init__(
component_context: Type[BaseContext] = ComponentContext,
context_menu_context: Type[BaseContext] = ContextMenuContext,
debug_scope: Absent["Snowflake_Type"] = MISSING,
default_integration_types: Absent[list[IntegrationType]] = MISSING,
delete_unused_application_cmds: bool = False,
disable_dm_commands: bool = False,
enforce_interaction_perms: bool = True,
@@ -356,6 +359,9 @@ def __init__(
self.auto_defer = auto_defer
"""A system to automatically defer commands after a set duration"""
self.intents = intents if isinstance(intents, Intents) else Intents(intents)
self.default_integration_types = cast(list[IntegrationType], default_integration_types) or [
IntegrationType.GUILD_INSTALL
]

# resources
if isinstance(proxy_auth, tuple):
@@ -1364,7 +1370,7 @@ def add_listener(self, listener: Listener) -> None:
c_listener for c_listener in self.listeners[listener.event] if not c_listener.is_default_listener
]

def add_interaction(self, command: InteractionCommand) -> bool:
def add_interaction(self, command: InteractionCommand) -> bool: # noqa: C901
"""
Add a slash command to the client.
@@ -1378,6 +1384,9 @@ def add_interaction(self, command: InteractionCommand) -> bool:
if self.disable_dm_commands:
command.dm_permission = False

if not command.integration_types:
command.integration_types = list(self.default_integration_types)

# for SlashCommand objs without callback (like objects made to hold group info etc)
if command.callback is None:
return False
2 changes: 1 addition & 1 deletion interactions/models/internal/application_commands.py
Original file line number Diff line number Diff line change
@@ -250,7 +250,7 @@ class InteractionCommand(BaseCommand):
)
nsfw: bool = attrs.field(repr=False, default=False, metadata=docs("This command should only work in NSFW channels"))
integration_types: list[Union[IntegrationType, int]] = attrs.field(
factory=lambda: [IntegrationType.GUILD_INSTALL],
factory=list,
repr=False,
metadata=docs("Installation context(s) where the command is available, only for globally-scoped commands."),
)

0 comments on commit f34d5db

Please sign in to comment.