Cogs¶
- clsCog.listener
- defbot_check
- defbot_check_once
- asynccog_after_invoke
- asynccog_before_invoke
- defcog_check
- asynccog_command_error
- defcog_unload
- defget_commands
- defget_listeners
- defhas_error_handler
- defwalk_commands
- class discord.Cog(*args: Any, **kwargs: Any)[исходный код]¶
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_commands()[исходный код]¶
- Результат:
A
listofApplicationCommands that are defined inside this cog.Примечание
This does not include subcommands.
- Тип результата:
- walk_commands()[исходный код]¶
An iterator that recursively walks through this cog’s commands and subcommands.
- get_listeners()[исходный код]¶
Returns a
listof (name, function) listener pairs that are defined in this cog.
- classmethod listener(name=..., once=False)[исходный код]¶
A decorator that marks a function as a listener.
This is the cog equivalent of
Bot.listen().
- has_error_handler()[исходный код]¶
Checks whether the cog has an error handler.
Добавлено в версии 1.7.
- Тип результата:
- cog_unload()[исходный код]¶
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)[исходный код]¶
A special method that registers as a
Bot.check_once()check.This function can be a coroutine and must take a sole parameter,
ctx, to represent theContextorApplicationContext.- Параметры:
ctx (
ApplicationContext) – The invocation context.- Тип результата:
- bot_check(ctx)[исходный код]¶
A special method that registers as a
Bot.check()check.This function can be a coroutine and must take a sole parameter,
ctx, to represent theContextorApplicationContext.- Параметры:
ctx (
ApplicationContext) – The invocation context.- Тип результата:
- cog_check(ctx)[исходный код]¶
A special method that registers as a
check()for every command and subcommand in this cog.This function can be a coroutine and must take a sole parameter,
ctx, to represent theContextorApplicationContext.- Параметры:
ctx (
ApplicationContext) – The invocation context.- Тип результата:
- await cog_command_error(ctx, error)[исходный код]¶
A special method that is called whenever an error is dispatched inside this cog.
This is similar to
on_command_error()except only applying to the commands inside this cog.This must be a coroutine.
- Параметры:
ctx (
ApplicationContext) – The invocation context where the error happened.error (
Exception) – The error that happened.
- Тип результата:
- await cog_before_invoke(ctx)[исходный код]¶
A special method that acts as a cog local pre-invoke hook.
This is similar to
ApplicationCommand.before_invoke().This must be a coroutine.
- Параметры:
ctx (
ApplicationContext) – The invocation context.- Тип результата:
- await cog_after_invoke(ctx)[исходный код]¶
A special method that acts as a cog local post-invoke hook.
This is similar to
ApplicationCommand.after_invoke().This must be a coroutine.
- Параметры:
ctx (
ApplicationContext) – The invocation context.- Тип результата:
- class discord.CogMeta(*args, **kwargs)[исходный код]¶
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(discord.CogMeta, abc.ABCMeta): pass class SomeMixin(metaclass=abc.ABCMeta): pass class SomeCogMixin(SomeMixin, discord.Cog, metaclass=CogABCMeta): pass
Примечание
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(discord.Cog, name='My Cog'): pass
- description¶
The cog description. By default, it is the cleaned docstring of the class.
Добавлено в версии 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(discord.Cog, command_attrs=dict(hidden=True)): @discord.slash_command() async def foo(self, ctx): pass # hidden -> True @discord.slash_command(hidden=False) async def bar(self, ctx): pass # hidden -> False
- Type:
- guild_ids¶
A shortcut to
command_attrs, whatguild_idsshould all application commands have in the cog. You can override this by settingguild_idsper command.Добавлено в версии 2.0.
- Type:
Optional[List[
int]]