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

sync_commands() raising Application command names must be unique #1383

Closed
3 tasks done
ArdaxHz opened this issue May 24, 2022 · 8 comments · Fixed by #2480
Closed
3 tasks done

sync_commands() raising Application command names must be unique #1383

ArdaxHz opened this issue May 24, 2022 · 8 comments · Fixed by #2480
Assignees
Labels
bug Something isn't working on hold priority: high High Priority
Milestone

Comments

@ArdaxHz
Copy link

ArdaxHz commented May 24, 2022

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

  • 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

No response

@ArdaxHz ArdaxHz added the unconfirmed bug A bug report that needs triaging label May 24, 2022
@maaaaaars
Copy link

Also experiencing the same issue with v2.0.0rc1

@XoutDragon
Copy link

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

@BridgeSenseDev
Copy link

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

@Lulalaby Lulalaby added the discord limitation Limitation imposed by discord label Jul 4, 2022
@Silver-Volt4
Copy link

Silver-Volt4 commented Sep 7, 2022

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.

@Dorukyum Dorukyum reopened this Sep 16, 2022
@Dorukyum Dorukyum self-assigned this Sep 16, 2022
@Dorukyum Dorukyum added bug Something isn't working and removed discord limitation Limitation imposed by discord unconfirmed bug A bug report that needs triaging labels Sep 16, 2022
@Lulalaby
Copy link
Member

Status Update please
@Pycord-Development/maintainers

@Lulalaby Lulalaby added this to the v2.5 milestone Feb 10, 2023
@homer2011
Copy link

Still having this issue on 2.5.0 dev release as of yesterday

@Dorukyum Dorukyum removed the on hold label Dec 2, 2023
@Dorukyum Dorukyum added the priority: high High Priority label Feb 3, 2024
@Lulalaby Lulalaby modified the milestones: v2.5, v2.6 Feb 29, 2024
@llimonix
Copy link

llimonix commented May 4, 2024

still present

@Vondyy
Copy link

Vondyy commented Jun 22, 2024

i have the issue

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

Successfully merging a pull request may close this issue.

10 participants