-
-
Save Ikusaba-san/69115b79d33e05ed07ec4a4f14db83b1 to your computer and use it in GitHub Desktop.
A list of all special cog methods
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from discord.ext import commands | |
class Cog(commands.Cog): | |
""" | |
Basic cog. | |
To set a custom name (e.g. put spaces or non-alphanumeric characters), use | |
the name kwarg. | |
e.g. | |
class Cog(commands.Cog, name='discord.py Commands'): | |
""" | |
def __init__(self, bot): | |
pass | |
# These checks can be async or non-async, doesn't matter. | |
async def cog_check(self, ctx): | |
"""I'm a local check that will be run on all commands in this cog!""" | |
async def bot_check(self, ctx): | |
"""I'm a global check that will be run on all commands!""" | |
async def bot_check_once(self, ctx): | |
"""I'm a global check that will be run on all commands ONCE.""" | |
# Before/After Invokers | |
async def cog_before_invoke(self, ctx): | |
"""I will be called before any commands in this cog will be invoked!""" | |
# (It's actually before the command callback is called) | |
async def cog_after_invoke(self, ctx): | |
"""I will be called after a command in this cog was executed!""" | |
# Other | |
def cog_unload(self): | |
"""I will clean up stuff!""" | |
async def cog_command_error(self, ctx, error): | |
"""I'm an error handler!""" | |
# An example listener, the decorator is required | |
@commands.Cog.listener() | |
async def on_message(self, message): | |
"""I listen to messages!""" | |
# Python 3.5: | |
# print('I got message from {0}!'.format(message.author)) | |
print(f'I got message from {message.author}!') | |
def setup(bot): | |
"""Required. You can do whatever you want here. Most common usage is to | |
simply add the cog. | |
""" | |
bot.add_cog(Cog(bot)) | |
def teardown(bot): | |
"""Optional. Cogs automatically get removed regardless of whether or not | |
this is here.""" | |
pass |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment