Skip to content
Discussion options

You must be logged in to vote

You can run an asynchronous method from __init__ by using loop.create_task.
create_task Schedules a task on your bot's event loop.

from discord.ext import commands


class MyCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot
        bot.loop.create_task(self.on_load())

    async def on_load(self):
        print(f'{self.qualified_name} loaded')

def setup(bot):
    bot.add_cog(MyCog(bot))

Additionally, you can always use on_ready; Keep in mind this event is not guaranteed to be called only once.

from discord.ext import commands


class MyCog(commands.Cog):
    def __init__(self, bot):
        self.bot = bot

    @commands.Cog.listener()
    async def on_ready(self):
  …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by ahiezx
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants