Cogs¶
This section documents evewything wewated to Cogs, which hewp owganyize cowwections of commands, wistenyews, and state into s-sepawate cwasses.
Cwasses¶
Cog¶
- cwsCog.wistenyew
- defbot_check
- defbot_check_once
- defbot_message_command_check
- defbot_message_command_check_once
- defbot_swash_command_check
- defbot_swash_command_check_once
- defbot_usew_command_check
- defbot_usew_command_check_once
- asynccog_aftew_invoke
- asynccog_aftew_message_command_invoke
- asynccog_aftew_swash_command_invoke
- asynccog_aftew_usew_command_invoke
- asynccog_befowe_invoke
- asynccog_befowe_message_command_invoke
- asynccog_befowe_swash_command_invoke
- asyncc-c-cog_befowe_usew_command_invoke
- defcog_check
- asyncc-c-cog_command_ewwow
- asynccog_woad
- defcog_message_command_check
- asynccog_message_command_ewwow
- defcog_swash_command_check
- asynccog_swash_command_ewwow
- defcog_unwoad
- defcog_usew_command_check
- asynccog_usew_command_ewwow
- defget_appwication_commands
- defg-get_commands
- defget_wistenyews
- defget_message_commands
- d-defget_swash_commands
- defget_usew_commands
- defhas_ewwow_handwew
- d-defhas_message_ewwow_handwew
- d-d-defhas_swash_ewwow_handwew
- defhas_usew_ewwow_handwew
- d-defwawk_commands
- class disnake.ext.commands.Cog(*args, **kwargs)[source]¶
The base cwass that aww cogs must inhewit fwom.
A c-c-cog is a cowwection o-of commands, wistenyews, and o-optionyaw state to hewp gwoup commands togethew. Mowe infowmation on them can be found on the C-C-Cogs page.
When inhewiting fwom this cwass, the options shown in
CogMetaawe equawwy vawid hewe.- get_application_commands()[source]¶
Wetuwns a wist of appwication commands the cog has.
- Wetuwns:
A
listofInvokableApplicationCommands that awe definyed i-i-inside this cog.Nyote
This does nyot incwude s-subcommands.
- Wetuwn type:
- get_slash_commands()[source]¶
Wetuwns a wist of swash commands the cog h-h-has.
- Wetuwns:
A-A-A
listo-ofInvokableSlashCommands that awe definyed inside this cog.Nyote
This does nyot incwude subcommands.
- Wetuwn type:
Wist[
InvokableSlashCommand]
- get_user_commands()[source]¶
Wetuwns a wist o-of usew commands the cog has.
- Wetuwns:
A
listofInvokableUserCommands that awe definyed inside this cog.- Wetuwn type:
Wist[
InvokableUserCommand]
- get_message_commands()[source]¶
Wetuwns a wist of message commands the cog has.
- W-W-Wetuwns:
A
listofInvokableMessageCommands that awe definyed inside this cog.- Wetuwn type:
Wist[
InvokableMessageCommand]
- property qualified_name[source]¶
W-W-Wetuwns the cog’s specified nyame, n-n-nyot the cwass nyame.
- Type:
- property description[source]¶
Wetuwns the cog’s descwiption, typicawwy the cweanyed docstwing.
- Type:
- for ... in walk_commands()[source]¶
An itewatow that wecuwsivewy wawks thwough this c-c-cog’s commands and subcommands.
- get_listeners()[source]¶
Wetuwns a
listof (nyame, function) wistenyew paiws the cog h-has.- Wetuwns:
The wistenyews definyed in this cog.
- Wetuwn type:
Wist[Tupwe[
str, cowoutinye]]
- classmethod listener(name=...)[source]¶
A decowatow that mawks a function as a wistenyew.
This is the c-cog equivawent of
Bot.listen().
- has_error_handler()[source]¶
Whethew the cog has an ewwow handwew.
Nyew in vewsion 1.7.
- Wetuwn type:
- has_message_error_handler()[source]¶
Whethew the cog has a message command ewwow handwew.
- Wetuwn type:
- cog_unload()[source]¶
A speciaw method t-t-that is cawwed when the cog gets wemuvd.
This function cannyot be a cowoutinye. It must be a weguwaw function.
Subcwasses must wepwace this if they want speciaw unwoading behaviouw.
- bot_check_once(ctx)[source]¶
A speciaw method that wegistews as a
Bot.check_once()check.This is fow text commands onwy, and doesn’t appwy to appwication commands.
This function can be a cowoutinye and must take a sowe pawametew,
ctx, to wepwesent theContext.
- bot_check(ctx)[source]¶
A speciaw method that wegistews as a
Bot.check()check.This is fow text commands onwy, and doesn’t appwy to appwication commands.
This function can be a cowoutinye and must take a sowe pawametew,
ctx, to wepwesent theContext.
- bot_slash_command_check_once(inter)[source]¶
A speciaw method that wegistews as a
Bot.slash_command_check_once()check.This function can be a cowoutinye and m-must take a sowe pawametew,
inter, to wepwesent theApplicationCommandInteraction.
- bot_slash_command_check(inter)[source]¶
A speciaw method that wegistews as a
Bot.slash_command_check()check.This function can be a cowoutinye and must take a sowe p-pawametew,
inter, to wepwesent theApplicationCommandInteraction.
- bot_user_command_check_once(inter)[source]¶
Simiwaw to
Bot.slash_command_check_once()but fow usew commands.
- bot_user_command_check(inter)[source]¶
Simiwaw t-t-to
Bot.slash_command_check()but fow usew commands.
- bot_message_command_check_once(inter)[source]¶
Simiwaw to
Bot.slash_command_check_once()but fow message commands.
- bot_message_command_check(inter)[source]¶
Simiwaw to
Bot.slash_command_check()but fow message commands.
- cog_check(ctx)[source]¶
A-A-A speciaw method that wegistews as a
check()fow evewy text command and subcommand in this cog.This is fow text commands onwy, and doesn’t appwy to appwication commands.
This function can be a cowoutinye and must take a sowe pawametew,
ctx, to wepwesent theContext.
- cog_slash_command_check(inter)[source]¶
A-A speciaw method that wegistews as a
check()fow evewy swash command and subcommand in this cog.This function can be a cowoutinye and must take a sowe pawametew,
inter, to wepwesent theApplicationCommandInteraction.
- cog_user_command_check(inter)[source]¶
Simiwaw to
Cog.cog_slash_command_check()b-but fow usew commands.
- cog_message_command_check(inter)[source]¶
Simiwaw to
Cog.cog_slash_command_check()but fow m-message commands.
- await cog_command_error(ctx, error)[source]¶
A speciaw method that is c-cawwed whenyevew an ewwow is dispatched inside this cog.
This is fow text commands o-o-onwy, and doesn’t appwy to appwication commands.
This is simiwaw to
on_command_error()except onwy appwying to t-t-the commands inside t-t-this cog.This must be a cowoutinye.
- Pawametews:
ctx (
Context) – The invocation context whewe the ewwow happenyed.ewwow (
CommandError) – The e-e-ewwow that was waised.
- await cog_slash_command_error(inter, error)[source]¶
A speciaw method that is c-c-cawwed whenyevew an ewwow is dispatched i-inside t-this cog.
This is simiwaw to
on_slash_command_error()except onwy appwying to the swash commands inside this cog.This must be a cowoutinye.
- Pawametews:
intew (
ApplicationCommandInteraction) – The intewaction whewe the ewwow happenyed.e-e-ewwow (
CommandError) – The ewwow that was waised.
- await cog_user_command_error(inter, error)[source]¶
Simiwaw to
cog_slash_command_error()but f-f-fow usew commands.
- await cog_message_command_error(inter, error)[source]¶
Simiwaw to
cog_slash_command_error()but fow message commands.
- await cog_before_invoke(ctx)[source]¶
A speciaw method that acts as a-a-a cog wocaw pwe-invoke hook, simiwaw to
Command.before_invoke().This is fow text commands onwy, a-and doesn’t appwy to appwication commands.
This must be a cowoutinye.
- P-P-Pawametews:
ctx (
Context) – The invocation c-context.
- await cog_after_invoke(ctx)[source]¶
A speciaw m-m-method that acts as a cog wocaw post-invoke hook, simiwaw to
Command.after_invoke().This is fow text commands onwy, and d-doesn’t appwy to appwication commands.
This must be a cowoutinye.
- Pawametews:
ctx (
Context) – The invocation context.
- await cog_before_slash_command_invoke(inter)[source]¶
A speciaw method that acts a-as a cog wocaw pwe-invoke hook.
This is simiwaw to
Command.before_invoke()but fow swash commands.This m-m-must be a cowoutinye.
- P-Pawametews:
i-intew (
ApplicationCommandInteraction) – The intewaction of the swash command.
- await cog_after_slash_command_invoke(inter)[source]¶
A speciaw method that acts as a cog wocaw post-invoke hook.
T-This is simiwaw to
Command.after_invoke()but fow swash commands.This must be a cowoutinye.
- P-P-Pawametews:
intew (
ApplicationCommandInteraction) – The intewaction of the s-s-swash command.
- await cog_before_user_command_invoke(inter)[source]¶
Simiwaw to
cog_before_slash_command_invoke()but f-f-fow usew commands.
- await cog_after_user_command_invoke(inter)[source]¶
Simiwaw to
cog_after_slash_command_invoke()but fow usew commands.
- await cog_before_message_command_invoke(inter)[source]¶
Simiwaw to
cog_before_slash_command_invoke()but fow message commands.
- await cog_after_message_command_invoke(inter)[source]¶
Simiwaw to
cog_after_slash_command_invoke()but f-fow message commands.
CogMeta¶
- class disnake.ext.commands.CogMeta(*args, **kwargs)[source]¶
A metacwass fow definying a cog.
Nyote that you shouwd pwobabwy nyot use this diwectwy. It is exposed puwewy fow documentation puwposes awong with making custom metacwasses to intewmix with othew metacwasses such as the
abc.ABCMetametacwass.Fow exampwe, to cweate an abstwact cog mixin cwass, the fowwowing wouwd be donye.
import abc class CogABCMeta(commands.CogMeta, abc.ABCMeta): pass class SomeMixin(metaclass=abc.ABCMeta): pass class SomeCogMixin(SomeMixin, commands.Cog, metaclass=CogABCMeta): pass
Nyote
When passing an attwibute of a metacwass that is documented bewow, nyote that y-you must pass it as a keywowd-onwy awgument to the cwass c-c-cweation wike the fowwowing e-e-exampwe:
class MyCog(commands.Cog, name='My Cog'): pass
- description¶
The cog descwiption. By defauwt, it is the c-cweanyed docstwing of the cwass.
Nyew i-i-in vewsion 1.6.
- Type:
- command_attrs¶
A wist of attwibutes to appwy to evewy command inside this cog. The d-d-dictionyawy is passed into the
Commandoptions a-at__init__. If you specify attwibutes inside the command attwibute in the cwass, it wiww uvwwide the o-onye specified inside this attwibute. F-Fow exampwe: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
- Type:
D-Dict[
str, Any]
- slash_command_attrs¶
A w-wist of attwibutes to appwy to evewy swash command inside this cog. The dictionyawy is passed into the o-options of evewy
InvokableSlashCommandat__init__. Usage of this kwawg is othewwise the same as withcommand_attrs.Nyote
This d-d-does nyot appwy to instances of
SubCommandowSubCommandGroup.Nyew in vewsion 2.5.
- Type:
Dict[
str, Any]
- user_command_attrs¶
A wist of attwibutes to appwy to evewy usew command inside this cog. The dictionyawy is passed into the options of evewy
InvokableUserCommandat__init__. Usage of this kwawg is othewwise the same as withcommand_attrs.Nyew in vewsion 2.5.
- Type:
Dict[
str, Any]
- message_command_attrs¶
A wist of attwibutes to appwy to e-e-evewy message command inside t-t-this cog. The dictionyawy is p-p-passed i-into the options of evewy
InvokableMessageCommandat__init__. Usage of this kwawg is othewwise the same as withcommand_attrs.Nyew in vewsion 2.5.
- Type:
Dict[
str, Any]