-
So I want to run a async function inside extension which is something equivalent to Sorry for my bad explanation.. any ideas? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
You can run an asynchronous method from 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 from discord.ext import commands
class MyCog(commands.Cog):
def __init__(self, bot):
self.bot = bot
@commands.Cog.listener()
async def on_ready(self):
print(f'{self.qualified_name} ready')
def setup(bot):
bot.add_cog(MyCog(bot)) |
Beta Was this translation helpful? Give feedback.
You can run an asynchronous method from
__init__
by using loop.create_task.create_task
Schedules a task on your bot's event loop.Additionally, you can always use
on_ready
; Keep in mind this event is not guaranteed to be called only once.