Skip to content

Commit aa1249b

Browse files
committed
add default contexts and integration_types values
1 parent d30c457 commit aa1249b

File tree

2 files changed

+27
-9
lines changed

2 files changed

+27
-9
lines changed

discord/bot.py

+24-1
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@
4848
UserCommand,
4949
command,
5050
)
51-
from .enums import InteractionType
51+
from .enums import InteractionType, InteractionContextType, IntegrationType
5252
from .errors import CheckFailure, DiscordException
5353
from .interactions import Interaction
5454
from .shard import AutoShardedClient
@@ -125,6 +125,10 @@ def add_application_command(self, command: ApplicationCommand) -> None:
125125

126126
if self._bot.debug_guilds and command.guild_ids is None:
127127
command.guild_ids = self._bot.debug_guilds
128+
if self._bot.default_command_contexts and command.contexts is None:
129+
command.contexts = self._bot.default_command_contexts
130+
if self._bot.default_command_integration_types and command.integration_types is None:
131+
command.integration_types = self._bot.default_command_integration_types
128132

129133
for cmd in self.pending_application_commands:
130134
if cmd == command:
@@ -1157,6 +1161,14 @@ def __init__(self, description=None, *args, **options):
11571161
self.auto_sync_commands = options.get("auto_sync_commands", True)
11581162

11591163
self.debug_guilds = options.pop("debug_guilds", None)
1164+
self.default_command_contexts = set(options.pop("default_command_contexts", {
1165+
InteractionContextType.guild,
1166+
InteractionContextType.bot_dm,
1167+
InteractionContextType.private_channel,
1168+
}))
1169+
self.default_command_integration_types = set(options.pop("default_command_integration_types", {
1170+
IntegrationType.guild_install,
1171+
}))
11601172

11611173
if self.owner_id and self.owner_ids:
11621174
raise TypeError("Both owner_id and owner_ids are set.")
@@ -1447,6 +1459,17 @@ class Bot(BotBase, Client):
14471459
:attr:`.process_application_commands` if the command is not found. Defaults to ``True``.
14481460
14491461
.. versionadded:: 2.0
1462+
default_command_contexts: Set[:class:`InteractionContextType`]
1463+
The default context types that the bot will use for commands.
1464+
Defaults to a set containing :attr:`InteractionContextType.guild`, :attr:`InteractionContextType.bot_dm`, and
1465+
:attr:`InteractionContextType.private_channel`.
1466+
1467+
.. versionadded:: 2.6
1468+
default_command_integration_types: Set[:class:`IntegrationType`]
1469+
The default integration types that the bot will use for commands.
1470+
Defaults to a set containing :attr:`IntegrationType.guild_install`.
1471+
1472+
.. versionadded:: 2.6
14501473
"""
14511474

14521475
@property

discord/commands/core.py

+3-8
Original file line numberDiff line numberDiff line change
@@ -1270,16 +1270,11 @@ def __init__(
12701270
"the 'contexts' and 'integration_types' parameters are not available for guild commands"
12711271
)
12721272

1273-
self.contexts: set[InteractionContextType] = contexts or {
1274-
InteractionContextType.guild,
1275-
InteractionContextType.bot_dm,
1276-
InteractionContextType.private_channel,
1277-
}
1273+
# These are set to None and their defaults are then set when added to the bot
1274+
self.contexts: set[InteractionContextType] | None = contexts
12781275
if guild_only:
12791276
self.guild_only: bool | None = guild_only
1280-
self.integration_types: set[IntegrationType] = integration_types or {
1281-
IntegrationType.guild_install
1282-
}
1277+
self.integration_types: set[IntegrationType] | None = integration_types
12831278

12841279
self.name_localizations: dict[str, str] = kwargs.get(
12851280
"name_localizations", MISSING

0 commit comments

Comments
 (0)