Skip to content

Commit f34d5db

Browse files
committedJan 21, 2025·
feat: Add client parameter for default Integration Type
1 parent 337c204 commit f34d5db

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed
 

‎interactions/client/client.py

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
Awaitable,
2929
Tuple,
3030
TypeVar,
31+
cast,
3132
overload,
3233
)
3334

@@ -96,6 +97,7 @@
9697
ComponentType,
9798
Intents,
9899
InteractionType,
100+
IntegrationType,
99101
Status,
100102
MessageFlags,
101103
)
@@ -296,6 +298,7 @@ def __init__(
296298
component_context: Type[BaseContext] = ComponentContext,
297299
context_menu_context: Type[BaseContext] = ContextMenuContext,
298300
debug_scope: Absent["Snowflake_Type"] = MISSING,
301+
default_integration_types: Absent[list[IntegrationType]] = MISSING,
299302
delete_unused_application_cmds: bool = False,
300303
disable_dm_commands: bool = False,
301304
enforce_interaction_perms: bool = True,
@@ -356,6 +359,9 @@ def __init__(
356359
self.auto_defer = auto_defer
357360
"""A system to automatically defer commands after a set duration"""
358361
self.intents = intents if isinstance(intents, Intents) else Intents(intents)
362+
self.default_integration_types = cast(list[IntegrationType], default_integration_types) or [
363+
IntegrationType.GUILD_INSTALL
364+
]
359365

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

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

1387+
if not command.integration_types:
1388+
command.integration_types = list(self.default_integration_types)
1389+
13811390
# for SlashCommand objs without callback (like objects made to hold group info etc)
13821391
if command.callback is None:
13831392
return False

‎interactions/models/internal/application_commands.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -250,7 +250,7 @@ class InteractionCommand(BaseCommand):
250250
)
251251
nsfw: bool = attrs.field(repr=False, default=False, metadata=docs("This command should only work in NSFW channels"))
252252
integration_types: list[Union[IntegrationType, int]] = attrs.field(
253-
factory=lambda: [IntegrationType.GUILD_INSTALL],
253+
factory=list,
254254
repr=False,
255255
metadata=docs("Installation context(s) where the command is available, only for globally-scoped commands."),
256256
)

0 commit comments

Comments
 (0)
Please sign in to comment.