Cogs
Cogs are an advanced feature of MeowerBot.py. They alow you to make & load reuseable commands and callbacks.
Creating a Cog
First thing you need to do is import a few things
from MeowerBot.cog import Cog
from MeowerBot.command import command, callback # callback is equivelent to listen
from MeowerBot import CallbackIds
To create a cog, it is as simple as defining a class. This is the basis for the reuseable part. Cogs are a singleton object. So when you define them they will only be defined once.
class YourCogName(Cog): pass
To create a command in a cog, you use the MeowerBot.command.command()
decorator.
It has the exact same interface as MeowerBot.bot.Bot.command()
from MeowerBot.context import Context
class YourCogName(Cog):
@command(name="hello")
async def hello(ctx: Context):
await ctx.reply("Hello, World!")
For creating listeners, its slightly more involved as it is done as the class instead of the instance. It is stil relitivly simple though, as you can just get the instance.
class YourCogName(Cog):
@callback(CallbackIds.login)
async def on_login(cls, token: str):
self = cls.__instance__
...
Creating and loading a cog
Creating a cog is easy, as it takes no arguments by default. Loading it is also easy, as you just call a single function with the cog instance on the bot object
bot.register_cog(YourCogName())