48
48
UserCommand ,
49
49
command ,
50
50
)
51
- from .enums import InteractionType
51
+ from .enums import IntegrationType , InteractionContextType , InteractionType
52
52
from .errors import CheckFailure , DiscordException
53
53
from .interactions import Interaction
54
54
from .shard import AutoShardedClient
@@ -125,6 +125,13 @@ def add_application_command(self, command: ApplicationCommand) -> None:
125
125
126
126
if self ._bot .debug_guilds and command .guild_ids is None :
127
127
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 (
131
+ self ._bot .default_command_integration_types
132
+ and command .integration_types is None
133
+ ):
134
+ command .integration_types = self ._bot .default_command_integration_types
128
135
129
136
for cmd in self .pending_application_commands :
130
137
if cmd == command :
@@ -271,7 +278,6 @@ def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool:
271
278
else :
272
279
as_dict = cmd .to_dict ()
273
280
to_check = {
274
- "dm_permission" : None ,
275
281
"nsfw" : None ,
276
282
"default_member_permissions" : None ,
277
283
"name" : None ,
@@ -287,6 +293,8 @@ def _check_command(cmd: ApplicationCommand, match: Mapping[str, Any]) -> bool:
287
293
"name_localizations" ,
288
294
"description_localizations" ,
289
295
],
296
+ "contexts" : None ,
297
+ "integration_types" : None ,
290
298
}
291
299
for check , value in to_check .items ():
292
300
if type (to_check [check ]) == list :
@@ -1157,6 +1165,21 @@ def __init__(self, description=None, *args, **options):
1157
1165
self .auto_sync_commands = options .get ("auto_sync_commands" , True )
1158
1166
1159
1167
self .debug_guilds = options .pop ("debug_guilds" , None )
1168
+ self .default_command_contexts = options .pop (
1169
+ "default_command_contexts" ,
1170
+ {
1171
+ InteractionContextType .guild ,
1172
+ InteractionContextType .bot_dm ,
1173
+ InteractionContextType .private_channel ,
1174
+ },
1175
+ )
1176
+
1177
+ self .default_command_integration_types = options .pop (
1178
+ "default_command_integration_types" ,
1179
+ {
1180
+ IntegrationType .guild_install ,
1181
+ },
1182
+ )
1160
1183
1161
1184
if self .owner_id and self .owner_ids :
1162
1185
raise TypeError ("Both owner_id and owner_ids are set." )
@@ -1167,6 +1190,20 @@ def __init__(self, description=None, *args, **options):
1167
1190
raise TypeError (
1168
1191
f"owner_ids must be a collection not { self .owner_ids .__class__ !r} "
1169
1192
)
1193
+ if not isinstance (self .default_command_contexts , collections .abc .Collection ):
1194
+ raise TypeError (
1195
+ f"default_command_contexts must be a collection not { self .default_command_contexts .__class__ !r} "
1196
+ )
1197
+ if not isinstance (
1198
+ self .default_command_integration_types , collections .abc .Collection
1199
+ ):
1200
+ raise TypeError (
1201
+ f"default_command_integration_types must be a collection not { self .default_command_integration_types .__class__ !r} "
1202
+ )
1203
+ self .default_command_contexts = set (self .default_command_contexts )
1204
+ self .default_command_integration_types = set (
1205
+ self .default_command_integration_types
1206
+ )
1170
1207
1171
1208
self ._checks = []
1172
1209
self ._check_once = []
@@ -1447,6 +1484,17 @@ class Bot(BotBase, Client):
1447
1484
:attr:`.process_application_commands` if the command is not found. Defaults to ``True``.
1448
1485
1449
1486
.. versionadded:: 2.0
1487
+ default_command_contexts: Collection[:class:`InteractionContextType`]
1488
+ The default context types that the bot will use for commands.
1489
+ Defaults to a set containing :attr:`InteractionContextType.guild`, :attr:`InteractionContextType.bot_dm`, and
1490
+ :attr:`InteractionContextType.private_channel`.
1491
+
1492
+ .. versionadded:: 2.6
1493
+ default_command_integration_types: Collection[:class:`IntegrationType`]]
1494
+ The default integration types that the bot will use for commands.
1495
+ Defaults to a set containing :attr:`IntegrationType.guild_install`.
1496
+
1497
+ .. versionadded:: 2.6
1450
1498
"""
1451
1499
1452
1500
@property
0 commit comments