Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

cannot name 2 application commands of different types the same name #954

Closed
3 tasks done
Revnoplex opened this issue Feb 7, 2022 · 23 comments · Fixed by #1208
Closed
3 tasks done

cannot name 2 application commands of different types the same name #954

Revnoplex opened this issue Feb 7, 2022 · 23 comments · Fixed by #1208
Assignees
Labels
bug Something isn't working

Comments

@Revnoplex
Copy link
Contributor

Revnoplex commented Feb 7, 2022

Summary

with version beta 4 i can no longer name 2 application commands the same name even though one is a slash command and one is a user command. this did not occur with version beta 1 and earlier.

Reproduction Steps

name 2 application commands of different types the same name.

Minimal Reproducible Code

#    create 2 application commands with the same name

#    first the slash command
@commands.slash_command(name='unmute', description="Unmute a user", guild_ids=config.slash_guilds)
@commands.has_permissions(manage_roles=True)
@commands.bot_has_permissions(manage_roles=True, send_messages=True)
async def slash_unmute(self, ctx, member: discord.Member, reason: discord.Option(str, "Reason for muting user",
                                                                                     required=False)):
    await self.unmute(ctx, member, reason)

#    now the context command
@commands.user_command(name='unmute', guild_ids=config.slash_guilds)
@commands.has_permissions(manage_roles=True)
@commands.bot_has_permissions(manage_roles=True, send_messages=True)
async def user_unmute(self, ctx, member: discord.Member):
    await self.unmute(ctx, member)

Expected Results

add both without a problem. like version beta 1 and earlier

Actual Results

gave the following exception:
Ignoring exception in on_connect
Traceback (most recent call last):
File "/bot-directory/venv/lib/python3.10/site-packages/discord/client.py", line 352, in _run_event
await coro(*args, **kwargs)
File "/bot-directory/venv/lib/python3.10/site-packages/discord/bot.py", line 1042, in on_connect
await self.sync_commands()
File "/bot-directory/venv/lib/python3.10/site-packages/discord/bot.py", line 552, in sync_commands
registered_guild_commands[guild_id] = await self.register_commands(
File "/bot-directory/venv/lib/python3.10/site-packages/discord/bot.py", line 460, in register_commands
registered.append(await register("edit", cmd["id"], cmd["command"].to_dict()))
File "/bot-directory/venv/lib/python3.10/site-packages/discord/http.py", line 338, in request
raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In description: Context menu commands cannot have description
In options: Context menu commands cannot have options

When trying to run a slash command. another error occurs:

Ignoring exception in on_interaction
Traceback (most recent call last):
File "/bot-directory/venv/lib/python3.10/site-packages/discord/bot.py", line 738, in process_application_commands
command = self._application_commands[interaction.data["id"]]
KeyError: '935791615111483445'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
File "/bot-directory/venv/lib/python3.10/site-packages/discord/client.py", line 352, in _run_event
await coro(*args, **kwargs)
File "/bot-directory/venv/lib/python3.10/site-packages/discord/bot.py", line 1048, in on_interaction
await self.process_application_commands(interaction)
File "/bot-directory/venv/lib/python3.10/site-packages/discord/bot.py", line 753, in process_application_commands
await self.sync_commands()
File "/bot-directory/venv/lib/python3.10/site-packages/discord/bot.py", line 555, in sync_commands
registered_guild_commands[guild_id] = await self.register_commands(
File "/bot-directory/venv/lib/python3.10/site-packages/discord/bot.py", line 461, in register_commands
registered.append(await register("edit", cmd["id"], cmd["command"].to_dict()))
File "/bot-directory/venv/lib/python3.10/site-packages/discord/http.py", line 338, in request
raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In description: Context menu commands cannot have description
In options: Context menu commands cannot have options

and sometimes it will not error but not register the context menu command

Intents

default intents, members and presences

System Information

  • Python v3.10.1-final
  • py-cord v2.0.0-beta
    • py-cord pkg_resources: v2.0.0b4
  • aiohttp v3.8.1
  • system info: Linux 5.13.0-28-generic Merge slash commands into master #31~20.04.1-Ubuntu SMP Wed Jan 19 14:08:10 UTC 2022

Checklist

  • I have searched the open issues for duplicates.
  • I have shown the entire traceback, if possible.
  • I have removed my token from display, if visible.

Additional Context

@Revnoplex Revnoplex added the unconfirmed bug A bug report that needs triaging label Feb 7, 2022
@Lulalaby
Copy link
Member

Lulalaby commented Feb 7, 2022

Are you sure that it is an error from pycord?
Did you accidentally set a context menu description and option somewhere?

@Revnoplex
Copy link
Contributor Author

context menu description and option?. Also this does not occur with beta 1

@Lulalaby
Copy link
Member

Lulalaby commented Feb 7, 2022

ok, we need more code for this to trace it back

@Revnoplex
Copy link
Contributor Author

can user commands not have descriptions?

@Revnoplex
Copy link
Contributor Author

nvm, i tested errors still occur when removing descriptions i could find

@Revnoplex
Copy link
Contributor Author

i need to run some tests on my bot code with context menu commands

@Revnoplex
Copy link
Contributor Author

i have edited the issue with all lines that declare context menu commands

@Revnoplex
Copy link
Contributor Author

im sorry but i gtg. I will continue to diagnose this in 20 hours. i am very busy and program my bot in my spare time

@Lulalaby
Copy link
Member

Lulalaby commented Feb 7, 2022

yeah, thank u!

@Lulalaby Lulalaby added bug Something isn't working and removed unconfirmed bug A bug report that needs triaging labels Feb 7, 2022
@Lulalaby Lulalaby self-assigned this Feb 7, 2022
@Revnoplex
Copy link
Contributor Author

I have noticed I have made a few errors in copying the code. I copied some of the wrong lines. I have temporarily corrected the lines to what I think they were. I will re-paste the correct lines in 18 hours when I have access to the latest bot code I am working on

@Lulalaby
Copy link
Member

Lulalaby commented Feb 7, 2022

All fine. We have time.
We wait

@Revnoplex
Copy link
Contributor Author

i have updated the reproduction code with the correct code and some extra info

@Lulalaby
Copy link
Member

Lulalaby commented Feb 8, 2022

thank you

@Lulalaby Lulalaby assigned BobDotCom and unassigned Lulalaby Feb 8, 2022
@Revnoplex
Copy link
Contributor Author

Revnoplex commented Feb 10, 2022

i have updated the issue with some extra errors

@Lulalaby Lulalaby assigned krittick and unassigned BobDotCom Feb 14, 2022
@Revnoplex Revnoplex changed the title more bugs with sync_commands() cannot name 2 application commands of different types the same name Feb 14, 2022
@Revnoplex
Copy link
Contributor Author

i have rewritten the issue because i found what the problem appears to be

@PaulMndn
Copy link

PaulMndn commented Feb 14, 2022

I just encountered the same bug and believe I might have found the error in the code.

To register the commands Bot().register_commands() is called. If force is set to False (Default), we encounter this bit of code in bot.py starting at line 434:

            for cmd in desynced:
                if cmd["action"] == "delete":
                    pending_actions.append(
                        {
                            "action": "delete",
                            "command": cmd["id"],
                            "name": cmd["command"],
                        }
                    )
                    continue
                # We can assume the command item is a command, since it's only a string if action is delete
                match = get(pending, name=cmd["command"].name)
                if match is None:
                    continue
                if cmd["action"] == "edit":
                    pending_actions.append(
                        {
                            "action": "edit",
                            "command": match,
                            "id": cmd["id"],
                        }
                    )

Going through the loop with cmd equal to the user command: If I take the example above, pending contains two elements: the SlashCommand with name "unmute" and the UserCommand with the name "unmute" in that order. Since get() is only performed using the name attribute, the first element with the matching name is returned, which due to the order of the pending is the SlashCommand object.
This results in a mismatched dict being appended to pending_actions and the UserCommand never gets registered.
Also, Bot.application_commands now contains the same SlashCommand twice.

The described behaviour happened on the second call of the function in my code.

This might be fixed by editing the get() call to use the id instead of the name. (suggestion, didn't actually verify this)

When I was debugging this I used version 2.0.0-beta3, the code snippet is from the current master.

@Revnoplex
Copy link
Contributor Author

Revnoplex commented Feb 15, 2022

im getting errors saying context menu errors for slash commands with the same name, after i have removed the user commands

@Revnoplex
Copy link
Contributor Author

i am able to get rid of this other error if i flush all application commands

@Revnoplex
Copy link
Contributor Author

Revnoplex commented Feb 15, 2022

i accidentally hit the application command limit while doing this. so only do it once

edit: the rate limit mysteriously disappeared. its supposed to last 24 hours

@BobDotCom
Copy link
Member

This issue should be fixed with #1208

@BobDotCom BobDotCom linked a pull request Apr 3, 2022 that will close this issue
8 tasks
@Revnoplex
Copy link
Contributor Author

This issue should be fixed with #1208

Ok, will test if the issue still occurs

@Revnoplex
Copy link
Contributor Author

can confirm this no longer occurs on the #1208 branch

@Revnoplex
Copy link
Contributor Author

Revnoplex commented Apr 5, 2022

ignore what said about before about everything being broken. I don't think it relates to this at all. I've been getting strange and unexpected behaviour with slash commands in general

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants