Skip to content

Commit 2f2b225

Browse files
committed
added autocomplete for registering global commands
1 parent 893f476 commit 2f2b225

File tree

1 file changed

+18
-12
lines changed

1 file changed

+18
-12
lines changed

discord/bot.py

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -214,15 +214,12 @@ async def sync_commands(self) -> None:
214214

215215
async def register_commands(self) -> None:
216216
"""|coro|
217-
218217
Registers all commands that have been added through :meth:`.add_application_command`.
219218
This method cleans up all commands over the API and should sync them with the internal cache of commands.
220219
This will only be rolled out to Discord if :meth:`.http.get_global_commands` has certain keys that differ from :data:`.pending_application_commands`
221-
222220
By default, this coroutine is called inside the :func:`.on_connect`
223221
event. If you choose to override the :func:`.on_connect` event, then
224222
you should invoke this coroutine as well.
225-
226223
.. versionadded:: 2.0
227224
"""
228225
commands_to_bulk = []
@@ -253,7 +250,7 @@ async def register_commands(self) -> None:
253250
if match:
254251
as_dict["id"] = match["id"]
255252

256-
keys_to_check = {"default_permission": True, "name": True, "description": True, "options": ["type", "name", "description"]}
253+
keys_to_check = {"default_permission": True, "name": True, "description": True, "options": ["type", "name", "description", "autocomplete", "choices"]}
257254
for key, more_keys in {
258255
key:more_keys
259256
for key, more_keys in keys_to_check.items()
@@ -262,14 +259,23 @@ async def register_commands(self) -> None:
262259
}.items():
263260
if key == "options":
264261
for i, option_dict in enumerate(as_dict[key]):
265-
for key2_change in [
266-
key2
267-
for key2 in more_keys
268-
if key2 in option_dict.keys() and key2 in match[key][i].keys()
269-
if option_dict[key2] != match[key][i][key2]
270-
]:
271-
# When a property in the options of a pending global command is changed
272-
needs_bulk = True
262+
if command.name == "recent":
263+
print(option_dict, "|||||", match[key][i])
264+
for key2 in more_keys:
265+
pendingVal = None
266+
if key2 in option_dict.keys():
267+
pendingVal = option_dict[key2]
268+
if pendingVal == False or pendingVal == []: # Registered commands are not available if choices is an empty array or if autocomplete is false
269+
pendingVal = None
270+
matchVal = None
271+
if key2 in match[key][i].keys():
272+
matchVal = match[key][i][key2]
273+
if matchVal == False or matchVal == []: # Registered commands are not available if choices is an empty array or if autocomplete is false
274+
matchVal = None
275+
276+
if pendingVal != matchVal:
277+
# When a property in the options of a pending global command is changed
278+
needs_bulk = True
273279
else:
274280
if as_dict[key] != match[key]:
275281
# When a property in a pending global command is changed

0 commit comments

Comments
 (0)