flask-discord-interactions icon indicating copy to clipboard operation
flask-discord-interactions copied to clipboard

Document and simplify clearing commands

Open dehnert opened this issue 9 months ago • 0 comments

Is your feature request related to a problem? Please describe.

When I autocomplete in a guild, my bot displays two versions of each command, which is disconcerting.

My assumption is that this is happening because I registered my commands globally (so they can be used in any guild it's added to) and also in the specific guild (for testing), as based on a suggestion in the docs:

You can optionally pass in a guild_id parameter. This will register the commands in a specific guild instead of registering them globally. This is the recommended approach for testing, since registering new global commands can take up to 1 hour.

Describe the solution you'd like

There's two requests I have to solve this:

  • The docs should mention that you should pick either global or guild-specific install, and avoid mixing them. I assumed they'd be de-duplicated. (Presumably the best practice is to have a "test" bot instance that installs commands in a few specific guilds, and runs on some test infrastructure; and a "prod" bot that installs commands globally. As long as updates to the "prod" bot are rare, the delay shouldn't matter much.)
  • Provide a discord.clear_commands() (or discord.update_commands(commands=[])) that allows removing the commands from a guild or globally, so that if somebody uses a single bot user and transitions from per-guild to global install, they can clear the existing commands appropriately.

Either of these would help somewhat, but I think ideally both would happen. I eventually realized that the problem was probably the per-guild + global commands, but even with docs to help with that, fixing it requires some way to clear commands out -- just removing the discord.update_commands() line presumably just leaves me with outdated commands installed globally.

(It would be nice to have a way to see the registered commands -- I'm not sure if this is available in the Discord UI somewhere. A Python function to do it would be handy, though maybe a little weird for this project...)

Describe alternatives you've considered

For clearing commands, an alternative approach seems to be:

discord_empty = DiscordInteractions(app)
discord_empty.update_commands()

but it feels clumsy, and especially without documentation of the problem and the solution, it's not especially obvious.

dehnert avatar Jan 24 '25 21:01 dehnert