Data Classes

Data Classes are objects that can be constructed by users and hold data. Most of these data classes do not have __slots__, meaning that they can have dynamic attributes.

CogContextMenuHolder

class discord_tools.app_commands.CogContextMenuHolder(cog)[source]

Represents a discord.ext.commands.Cog or discord.ext.commands.GroupCog context menu holder.

Added in version 1.0.

Parameters:

cog (Union[discord.ext.commands.Cog, discord.ext.commands.GroupCog]) – The cog this context menu holder belongs to.

classmethod context_menu(*, name=..., nsfw=False, auto_locale_strings=True, extras=...)[source]

A decorator that makes a function a context menu.

Unlike discord.app_commands.context_menu() this is designed for cogs only.

Parameters:
  • name (Union[str, discord.app_commands.locale_str]) – The name of the context menu command. If not given, it defaults to a title-case version of the callback name. Note that unlike regular slash commands this can have spaces and upper case characters in the name.

  • nsfw (bool) – Whether the command is NSFW and should only work in NSFW channels. Defaults to False. Due to a Discord limitation, this does not work on subcommands.

  • auto_locale_strings (bool) – If this is set to True, then all translatable strings will implicitly be wrapped into discord.app_commands.locale_str rather than str. This could avoid some repetition and be more ergonomic for certain defaults such as default command names, command descriptions, and parameter names. Defaults to True.

  • extras (dict) – A dictionary that can be used to store extraneous data.

property context_menus

Returns all the context menus that this holder has loaded.

Type:

List[discord.app_commands.ContextMenu]

load_menus()[source]

Loads all the context menus to this holder.

Note

This does not add it to the tree, you must call add_to_tree() for the commands to be added to the tree.

add_to_tree(*, tree=...)[source]

Adds the context menus to the command tree.

If no tree is passed then it tries to resolve to cog.bot or cog.client, and after that, bot.tree.

Raises:

RuntimeError – No client/bot found on the cog.

Parameters:

tree (discord.app_commands.CommandTree) – The tree to add the context menus to.

remove_menu(menu)[source]

Removes a menu from this holder.

Note

This does not remove it from the tree.

Parameters:

menu (str) – The context menu name to remove.

Returns:

The context menu that was removed, or None.

Return type:

Optional[discord.app_commands.ContextMenu]

clear()[source]

Clears all the current menus in this holder.

Note

This does not clear them from the tree.