Search code examples
pythondiscorddiscord.pypycord

Py-cord command won't let go


I have been trying to update my discord bot to discord.py v2.0 and wanted to switch over to slash commands and cogs. When trying different techniques of achieving this I once used py-cord. I created a test command called latency and it worked but since I struggled with py-cord I uninstalled py-cord and found a new technique. The problem is that the latency (my py-cord) command is still there on the list where you can choose what slash command to use and so I wonder how do I remove this from the bot command selection?


Solution

  • When working with slash commands, the discord API registers and deregisters the slash commands on their own servers, and then sets up hooks for your bot.

    This means that, when the bot connects, it sends an API call to discord to tell it what commands it has, after which you need to wait for Discord to register that properly. They don't guarantee to do that instantly, not for deletion nor registration.

    So, in short, you don't remove it from the bot section; you wait until Discord does that for you. They guarantee that they do that in 24 hours of your bot being online, but, realistically, it's usually done in less than 2.

    You can set debug_guilds if you want to register commands faster, which would allow you to have a few guilds (servers) that would get updated first, usually quite close to immediately. However, from my own experience, that helped very little for deletion, as Discord usually took its time for that.

    One more advantage of debug_guilds is that, when passed, any new or deleted commands are only registered for those specific guilds, allowing you for more free testing. However, it is not perfect, as changed excising commands are of course still run trough your testing bot.

    Instead, my advice would be this: Create a second bot, and use that one for testing stuff. Once it's done, you can update the new bot with the verified code. This way, no one gets annoyed at multiple registered commands and all that! If you know how to use git: just run one bot on the main branch, and the other on the development branch. :-)

    I hope this helps! :-)