Skip to content

Review uses of on_ready in cogs #101

@pydis-bot

Description

@pydis-bot

Originally posted by Scragly:

There are 12 cogs that use the event on_ready to perform some form of preparation for that cog.

While that's fine if the extension is loaded before the bot is started, any cases where loading occurs after this stage will result in the preparatory tasks not being done at all, resulting in missing data the cogs rely on to function. This includes cases where a cog may be reloaded during runtime, which often happens during development to refresh to code.

Instead of running when the bot dispatches the ready event, it would be best to instead have it prepare every time a cog is loaded, but have it wait for the bot's ready flag:

class Cog:
    def __init__(self, bot):
        self.bot = bot
        ...
        bot.loop.create_task(self.prepare_method())

    async def prepare_method(self):
        await self.bot.wait_until_ready()
        # do prep stuff
        ...

This is a job for after the Github migration.

Metadata

Metadata

Assignees

No one assigned

    Labels

    a: backendRelated to internal functionality and utilities (error_handler, logging, security, utils and core)t: bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions