Tree

Red uses a subclass of discord.py’s CommandTree object in order to allow Cog Creators to add application commands to their cogs without worrying about the command count limit and to support caching AppCommand objects. When an app command is added to the bot’s tree, it will not show up in tree.get_commands or other similar methods unless the command is “enabled” with [p]slash enable (similar to “load”ing a cog) and tree.red_check_enabled has been run since the command was added to the tree.

Note

If you are adding app commands to the tree during load time, the loading process will call tree.red_check_enabled for your cog and its app commands. If you are adding app commands to the bot outside of load time, a call to tree.red_check_enabled after adding the commands is required to ensure the commands will appear properly.

If application commands from your cog show up in [p]slash list as enabled from an (unknown) cog and disabled from your cog at the same time, you did not follow the instructions above. You must manually call tree.red_check_enabled after adding the commands to the tree.

RedTree

class redbot.core.tree.RedTree(*args, **kwargs)[source]

Bases: CommandTree

A container that holds application command information.

Internally does not actually add commands to the tree unless they are enabled with [p]slash enable, to support Red’s modularity. See discord.app_commands.CommandTree for more information.

add_command(command, /, *args, guild=..., guilds=..., override=False, **kwargs)[source]

Adds an application command to the tree.

Commands will be internally stored until enabled by [p]slash enable.

clear_commands(*args, guild, type=None, **kwargs)[source]

Clears all application commands from the tree.

await interaction_check(interaction)[source]

Global checks for app commands.

await on_error(interaction, error, /, *args, **kwargs)[source]

Fallback error handler for app commands.

await red_check_enabled()[source]

Restructures the commands in this tree, enabling commands that are enabled and disabling commands that are disabled.

After running this function, the tree will be populated with enabled commands only. If commands are manually added to the tree outside of the standard cog loading process, this must be run for them to be usable.

remove_command(command, /, *args, guild=None, type=<AppCommandType.chat_input: 1>, **kwargs)[source]

Removes an application command from this tree.

await sync(*args, guild=None, **kwargs)[source]

Wrapper to store command IDs when commands are synced.