Skip to content

app_commands: handle empty guild_ids list #10208

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

Open
wants to merge 2 commits into
base: master
Choose a base branch
from

Conversation

laggron42
Copy link
Contributor

Summary

If an app command has guild_ids=[] or @app_commands.guilds() with no arguments, I'd expect the command to be detected as non-global command (despite not having guilds). However, this isn't the case and the command will be marked as global and synced everywhere.

When handling a command's guild_ids, most of the time an explicit check is made (if guild_ids is not None), which makes a difference between None and an empty list, but a few places missed this by using guild_ids or ..., where both None and [] will evaluate to false.

I fixed this behavior with an explicit check everywhere, making it possible to have guild commands that don't have a list of guilds yet (which can then be dynamically configured later on).

Checklist

  • If code changes were made then they have been tested.
    • I have updated the documentation to reflect the changes.
  • This PR fixes an issue.
  • This PR adds something new (e.g. new method or parameters).
  • This PR is a breaking change (e.g. methods or parameters removed/renamed)
  • This PR is not a code change (e.g. documentation, README, ...)

@DA-344
Copy link
Contributor

DA-344 commented Jun 15, 2025

Which use case do you have to pass guilds with no arguments? Commands that are not global must be scoped to certain guilds, else, it's like they not exist

@laggron42
Copy link
Contributor Author

The use case is when the list of guilds is provided by a data source whose initial state is empty.

In my case, I have an admin command which should only exist in servers chosen by the bot owner. The bot owner can register new servers to sync using a text command like !config syncadmin (and manage existing ones afterwards).
It works fine, except for the initial case where no servers have been registered, and discord.py will make it global instead. Since that command is in a cog, it will be picked up by the command tree and synced (unless I force remove it during cog loading, which is another solution but feels dirty).

I know not having guilds means the command essentially doesn't exist like you said, but it is something I am managing dynamically later on.
Besides, most of the code already supports that logic123, it feels like that behavior was intended from the start, but was forgotten about with later commits (like 02fcc81).

Footnotes

  1. https://github.com/Rapptz/discord.py/blob/master/discord/app_commands/tree.py#L387

  2. https://github.com/Rapptz/discord.py/blob/master/discord/app_commands/tree.py#L368

  3. https://github.com/Rapptz/discord.py/blob/master/discord/app_commands/commands.py#L706

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants