pycord icon indicating copy to clipboard operation
pycord copied to clipboard

sync_commands() raising Application command names must be unique

Open ArdaxHz opened this issue 3 years ago • 8 comments

Summary

Application command names must be unique raised when calling sync_commands() method

Reproduction Steps

When I unload/load/reload a cogs using bot.unload_extension(), etc. I also call the bot.sync_commands() method as unloading the extension doesn't unload the commands from discord.

Minimal Reproducible Code

@bridge.bridge_command(hidden=True)
    @commands.is_owner()
    async def unload(self, ctx: commands.Context, extension: str):
        extension = extension.lower()
        path = None
        if extension in self._iterdir_names(self.bot.cogs_path):
            path = self.cogs_folder
        elif extension in self._iterdir_names(self.bot.extensions_path):
            path = self.bot.extensions_path.name

        if path is not None:
            print(f"Unloading {path}.{extension}")
            self.bot.unload_extension(f"{path}.{extension}")
            print(f"Unloaded {path}.{extension}")
            await ctx.reply(f"Unloaded {path}.{extension}", delete_after=3)
        else:
            logging.warning(
                f"{extension} doesn't exist in the cogs or extensions folder."
            )

        await self.bot.sync_commands()

Expected Results

The sync command to update the bot's commands on the discord api to match those of the bots.

Actual Results

  File "C:\Users\<user>\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\commands\core.py", line 126, in wrapped
    ret = await coro(arg)
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\commands\core.py", line 856, in _invoke
    await self.callback(self.cog, ctx, **kwargs)
  File "E:\Docs\discord bot\cogs\basehelpercommands.py", line 43, in load
    else:
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\bot.py", line 629, in sync_commands
    registered_commands = await self.register_commands(
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\bot.py", line 529, in register_commands
    registered = await register("bulk", data, _log=False)
  File "C:\Users\<user>\AppData\Local\Programs\Python\Python39\lib\site-packages\discord\http.py", line 359, in request
    raise HTTPException(response, data)
discord.errors.HTTPException: 400 Bad Request (error code: 50035): Invalid Form Body
In 12: Application command names must be unique

Intents

intents = discord.Intents.default() intents.message_content = True

System Information

  • Python v3.9.7-final
  • py-cord v2.0.0-candidate
    • py-cord pkg_resources: v2.0.0rc1
  • aiohttp v3.7.4.post0
  • system info: Windows 10 10.0.19043

Checklist

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

Additional Context

No response

ArdaxHz avatar May 24 '22 22:05 ArdaxHz

Also experiencing the same issue with v2.0.0rc1

maaaaaars avatar Jun 01 '22 11:06 maaaaaars

Am experiencing this too when I sync when loading extensions then unloading extenstions.

XoutDragon avatar Jun 12 '22 21:06 XoutDragon

Also having the same issue even when theres only 2 slash commands and their names are unique

BridgeSenseDev avatar Jun 20 '22 14:06 BridgeSenseDev

I have investigated this a bit more and found a temporary hack to fix OP's error. TLDR: Run bot._pending_application_commands = [] before your reloading code.

Slash commands added by decorators are stored in _pending_application_commands. sync_commands() uses this list when you do not pass an argument. This list is not cleared when you unload and reload your extensions.

img

Here I've printed out the contents of _pending_application_commands twice, before and after reloading. The list doubled in size and included duplicates of commands, causing the error in question.

Manually clearing the array before reloading fixed this for me, but it may break something I'm not aware of.

silver-volt4 avatar Sep 07 '22 15:09 silver-volt4

Status Update please @Pycord-Development/maintainers

Lulalaby avatar Sep 23 '22 00:09 Lulalaby

Still having this issue on 2.5.0 dev release as of yesterday

homer2011 avatar Aug 30 '23 13:08 homer2011

still present

llimonix avatar May 04 '24 17:05 llimonix

i have the issue

AlexTheGoat69 avatar Jun 22 '24 15:06 AlexTheGoat69