You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository was archived by the owner on Sep 3, 2023. It is now read-only.
The process of making a command (slash/text) is simple. You can either use Cogs, or just have them as separate methods/functions in a file. Emperor uses Cogs. Imagine cogs as categories that hold the same commands under them, meaning a grouping of relevant commands.
The starting point of a Cog is as follows:
fromdiscord.extimportcommandsimportdiscordclassNewCog(commands.Cog):
"""The description for NewCog goes here."""def__init__(self, bot):
self.bot=botasyncdefcog_load(self):
# loading logic goes herepassasyncdefcog_unload(self):
# clean up logic goes herepassasyncdefcog_check(self, ctx):
# checks that apply to every command in herereturnTrueasyncdefcog_command_error(self, ctx, error):
# error handling to every command in herepassasyncdefcog_app_command_error(self, interaction, error):
# error handling to every application command in herepassasyncdefcog_after_invoke(self, ctx):
# called after a command is called herepassasyncdefsetup(bot):
awaitbot.add_cog(NewCog(bot))
As you can see, a cog is a class which holds methods that are either events or commands. Inside a cog, it holds a lot of stuff from commands to methods that are reserved by discord.py lib for error handling/code execution at certain points. Knowing the difference between how you can spot a command, event and a method reserved by discord.py is key to knowing how the commands work.
The definite way to know whether a method is an event or a command is first to look at the Special Methods that cogs inherit from commands.Cogs. These methods are used to log or execute code whenever the cog is loaded or unloaded, check for errors depending on the type of command that has the problem, etc. This is to just know if the method is reserved by discord.py.
Going back to figuring out if you have an event or command method, is to look at the decorators. If you see either @app_commands or @commands, the method is a command. You can figure out what the command does as both will have a .command(name="", descriptions="") method.
To figure out events, to see if they are a .listener() and the method names follows an event.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The process of making a command (slash/text) is simple. You can either use Cogs, or just have them as separate methods/functions in a file.
Emperor uses Cogs. Imagine cogs as categories that hold the same commands under them, meaning a grouping of relevant commands.
The starting point of a Cog is as follows:
As you can see, a cog is a class which holds methods that are either events or commands. Inside a cog, it holds a lot of stuff from commands to methods that are reserved by
discord.pylib for error handling/code execution at certain points. Knowing the difference between how you can spot a command, event and a method reserved bydiscord.pyis key to knowing how the commands work.The definite way to know whether a method is an event or a command is first to look at the Special Methods that cogs inherit from
commands.Cogs. These methods are used to log or execute code whenever the cog is loaded or unloaded, check for errors depending on the type of command that has the problem, etc. This is to just know if the method is reserved bydiscord.py.Going back to figuring out if you have an event or command method, is to look at the decorators. If you see either
@app_commandsor@commands, the method is a command. You can figure out what the command does as both will have a.command(name="", descriptions="")method.To figure out events, to see if they are a
.listener()and the method names follows an event.References
Beta Was this translation helpful? Give feedback.
All reactions