Way to run an async function immediately? #7467
-
Is it possible to run an async function such as guild.create_text_channel() immediately rather being put at the back of the queue? Particularly, I want to make sure everything in my on_ready() function finishes running before any other events are processed. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
If all you're doing is making HTTP requests, you can just manually make those requests before starting up the bot. See how it's done under the hood in |
Beta Was this translation helpful? Give feedback.
-
I'm writing this in another comment because this is probably the answer you're looking for. You could create something that acts similar to For example: import asyncio
import discord
class MyBot(discord.Client):
def __init__(self):
super().__init__()
self.my_event = asyncio.Event()
async def wait_until_actually_ready(self):
return await self.my_event.wait()
async def on_ready(self):
... # do whatever processing you need to here
# self.get_channel() etc etc
self.my_event.set()
async def on_message(self, message):
await self.wait_until_actually_ready() # wait until we've done things in on_ready
... # your actual event listener code
bot = MyBot()
bot.run(...) This will make your |
Beta Was this translation helpful? Give feedback.
I'm writing this in another comment because this is probably the answer you're looking for.
You could create something that acts similar to
bot.wait_until_ready()
using anasyncio.Event
.For example: