Cogs¶
This section documents everything related to Cogs, which help organize collections of commands, listeners, and state into separate classes.
Classes¶
Cog¶
- clsCog.listener
- defbot_check
- defbot_check_once
- defbot_message_command_check
- defbot_message_command_check_once
- defbot_slash_command_check
- defbot_slash_command_check_once
- defbot_user_command_check
- defbot_user_command_check_once
- asynccog_after_invoke
- asynccog_after_message_command_invoke
- asynccog_after_slash_command_invoke
- asynccog_after_user_command_invoke
- asynccog_before_invoke
- asynccog_before_message_command_invoke
- asynccog_before_slash_command_invoke
- asynccog_before_user_command_invoke
- defcog_check
- asynccog_command_error
- asynccog_load
- defcog_message_command_check
- asynccog_message_command_error
- defcog_slash_command_check
- asynccog_slash_command_error
- defcog_unload
- defcog_user_command_check
- asynccog_user_command_error
- defget_application_commands
- defget_commands
- defget_listeners
- defget_message_commands
- defget_slash_commands
- defget_user_commands
- defhas_error_handler
- defhas_message_error_handler
- defhas_slash_error_handler
- defhas_user_error_handler
- defwalk_commands
- class disnake.ext.commands.Cog(*args, **kwargs)[source]¶
- The base class that all cogs must inherit from. - A cog is a collection of commands, listeners, and optional state to help group commands together. More information on them can be found on the Cogs page. - When inheriting from this class, the options shown in - CogMetaare equally valid here.- get_application_commands()[source]¶
- Returns a list of application commands the cog has. - Returns:
- A - listof- InvokableApplicationCommands that are defined inside this cog.- Note - This does not include subcommands. 
- Return type:
 
 - get_slash_commands()[source]¶
- Returns a list of slash commands the cog has. - Returns:
- A - listof- InvokableSlashCommands that are defined inside this cog.- Note - This does not include subcommands. 
- Return type:
 
 - get_user_commands()[source]¶
- Returns a list of user commands the cog has. - Returns:
- A - listof- InvokableUserCommands that are defined inside this cog.
- Return type:
 
 - get_message_commands()[source]¶
- Returns a list of message commands the cog has. - Returns:
- A - listof- InvokableMessageCommands that are defined inside this cog.
- Return type:
 
 - for ... in walk_commands()[source]¶
- An iterator that recursively walks through this cog’s commands and subcommands. 
 - get_listeners()[source]¶
- Returns a - listof (name, function) listener pairs the cog has.- Returns:
- The listeners defined in this cog. 
- Return type:
 
 - classmethod listener(name=...)[source]¶
- A decorator that marks a function as a listener. - This is the cog equivalent of - Bot.listen().
 - has_message_error_handler()[source]¶
- Whether the cog has a message command error handler. - Return type:
 
 - cog_unload()[source]¶
- A special method that is called when the cog gets removed. - This function cannot be a coroutine. It must be a regular function. - Subclasses must replace this if they want special unloading behaviour. 
 - bot_check_once(ctx)[source]¶
- A special method that registers as a - Bot.check_once()check.- This is for text commands only, and doesn’t apply to application commands. - This function can be a coroutine and must take a sole parameter, - ctx, to represent the- Context.
 - bot_check(ctx)[source]¶
- A special method that registers as a - Bot.check()check.- This is for text commands only, and doesn’t apply to application commands. - This function can be a coroutine and must take a sole parameter, - ctx, to represent the- Context.
 - bot_slash_command_check_once(inter)[source]¶
- A special method that registers as a - Bot.slash_command_check_once()check.- This function can be a coroutine and must take a sole parameter, - inter, to represent the- ApplicationCommandInteraction.
 - bot_slash_command_check(inter)[source]¶
- A special method that registers as a - Bot.slash_command_check()check.- This function can be a coroutine and must take a sole parameter, - inter, to represent the- ApplicationCommandInteraction.
 - bot_user_command_check_once(inter)[source]¶
- Similar to - Bot.slash_command_check_once()but for user commands.
 - bot_user_command_check(inter)[source]¶
- Similar to - Bot.slash_command_check()but for user commands.
 - bot_message_command_check_once(inter)[source]¶
- Similar to - Bot.slash_command_check_once()but for message commands.
 - bot_message_command_check(inter)[source]¶
- Similar to - Bot.slash_command_check()but for message commands.
 - cog_check(ctx)[source]¶
- A special method that registers as a - check()for every text command and subcommand in this cog.- This is for text commands only, and doesn’t apply to application commands. - This function can be a coroutine and must take a sole parameter, - ctx, to represent the- Context.
 - cog_slash_command_check(inter)[source]¶
- A special method that registers as a - check()for every slash command and subcommand in this cog.- This function can be a coroutine and must take a sole parameter, - inter, to represent the- ApplicationCommandInteraction.
 - cog_user_command_check(inter)[source]¶
- Similar to - Cog.cog_slash_command_check()but for user commands.
 - cog_message_command_check(inter)[source]¶
- Similar to - Cog.cog_slash_command_check()but for message commands.
 - await cog_command_error(ctx, error)[source]¶
- A special method that is called whenever an error is dispatched inside this cog. - This is for text commands only, and doesn’t apply to application commands. - This is similar to - on_command_error()except only applying to the commands inside this cog.- This must be a coroutine. - Parameters:
- ctx ( - Context) – The invocation context where the error happened.
- error ( - CommandError) – The error that was raised.
 
 
 - await cog_slash_command_error(inter, error)[source]¶
- A special method that is called whenever an error is dispatched inside this cog. - This is similar to - on_slash_command_error()except only applying to the slash commands inside this cog.- This must be a coroutine. - Parameters:
- inter ( - ApplicationCommandInteraction) – The interaction where the error happened.
- error ( - CommandError) – The error that was raised.
 
 
 - await cog_user_command_error(inter, error)[source]¶
- Similar to - cog_slash_command_error()but for user commands.
 - await cog_message_command_error(inter, error)[source]¶
- Similar to - cog_slash_command_error()but for message commands.
 - await cog_before_invoke(ctx)[source]¶
- A special method that acts as a cog local pre-invoke hook, similar to - Command.before_invoke().- This is for text commands only, and doesn’t apply to application commands. - This must be a coroutine. - Parameters:
- ctx ( - Context) – The invocation context.
 
 - await cog_after_invoke(ctx)[source]¶
- A special method that acts as a cog local post-invoke hook, similar to - Command.after_invoke().- This is for text commands only, and doesn’t apply to application commands. - This must be a coroutine. - Parameters:
- ctx ( - Context) – The invocation context.
 
 - await cog_before_slash_command_invoke(inter)[source]¶
- A special method that acts as a cog local pre-invoke hook. - This is similar to - Command.before_invoke()but for slash commands.- This must be a coroutine. - Parameters:
- inter ( - ApplicationCommandInteraction) – The interaction of the slash command.
 
 - await cog_after_slash_command_invoke(inter)[source]¶
- A special method that acts as a cog local post-invoke hook. - This is similar to - Command.after_invoke()but for slash commands.- This must be a coroutine. - Parameters:
- inter ( - ApplicationCommandInteraction) – The interaction of the slash command.
 
 - await cog_before_user_command_invoke(inter)[source]¶
- Similar to - cog_before_slash_command_invoke()but for user commands.
 - await cog_after_user_command_invoke(inter)[source]¶
- Similar to - cog_after_slash_command_invoke()but for user commands.
 - await cog_before_message_command_invoke(inter)[source]¶
- Similar to - cog_before_slash_command_invoke()but for message commands.
 - await cog_after_message_command_invoke(inter)[source]¶
- Similar to - cog_after_slash_command_invoke()but for message commands.
 
CogMeta¶
- class disnake.ext.commands.CogMeta(*args, **kwargs)[source]¶
- A metaclass for defining a cog. - Note that you should probably not use this directly. It is exposed purely for documentation purposes along with making custom metaclasses to intermix with other metaclasses such as the - abc.ABCMetametaclass.- For example, to create an abstract cog mixin class, the following would be done. - import abc class CogABCMeta(commands.CogMeta, abc.ABCMeta): pass class SomeMixin(metaclass=abc.ABCMeta): pass class SomeCogMixin(SomeMixin, commands.Cog, metaclass=CogABCMeta): pass - Note - When passing an attribute of a metaclass that is documented below, note that you must pass it as a keyword-only argument to the class creation like the following example: - class MyCog(commands.Cog, name='My Cog'): pass - description¶
- The cog description. By default, it is the cleaned docstring of the class. - New in version 1.6. - Type:
 
 - command_attrs¶
- A list of attributes to apply to every command inside this cog. The dictionary is passed into the - Commandoptions at- __init__. If you specify attributes inside the command attribute in the class, it will override the one specified inside this attribute. For example:- class MyCog(commands.Cog, command_attrs=dict(hidden=True)): @commands.command() async def foo(self, ctx): pass # hidden -> True @commands.command(hidden=False) async def bar(self, ctx): pass # hidden -> False 
 - slash_command_attrs¶
- A list of attributes to apply to every slash command inside this cog. The dictionary is passed into the options of every - InvokableSlashCommandat- __init__. Usage of this kwarg is otherwise the same as with- command_attrs.- Note - This does not apply to instances of - SubCommandor- SubCommandGroup.- New in version 2.5. 
 - user_command_attrs¶
- A list of attributes to apply to every user command inside this cog. The dictionary is passed into the options of every - InvokableUserCommandat- __init__. Usage of this kwarg is otherwise the same as with- command_attrs.- New in version 2.5. 
 - message_command_attrs¶
- A list of attributes to apply to every message command inside this cog. The dictionary is passed into the options of every - InvokableMessageCommandat- __init__. Usage of this kwarg is otherwise the same as with- command_attrs.- New in version 2.5.