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¶
- clsCogContextMenuHolder.context_menu
- defadd_to_tree
- defclear
- defload_menus
- defremove_menu
- class discord_tools.app_commands.CogContextMenuHolder(cog)[source]¶
Represents a
discord.ext.commands.Cogordiscord.ext.commands.GroupCogcontext 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 toFalse. Due to a Discord limitation, this does not work on subcommands.auto_locale_strings (
bool) – If this is set toTrue, then all translatable strings will implicitly be wrapped intodiscord.app_commands.locale_strrather thanstr. This could avoid some repetition and be more ergonomic for certain defaults such as default command names, command descriptions, and parameter names. Defaults toTrue.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:
- 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
treeis passed then it tries to resolve tocog.botorcog.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]