#Is there any example of a bot that uses bot.start(token) instad of bot.run
1 messages · Page 1 of 1 (latest)
I don’t think there are any examples, but it is pretty straightforward to use
Sorry, I was thinking of examples on the repo
import asyncio
import discord
bot = discord.Bot()
# …
async def main():
# other things to start before the bot starts
await thingOne()
await thingTwo()
await bot.start("token")
asyncio.run(main())
Here’s a usage example if you need one
No problem
Oh on this just to see what the limits are would it be possible to open 2 discord clients. Not doing that, but slack socket mode is really similar to how the discord client works
I think so, but I'm not positive
You’re welcome
so just tested in this instance discord would still be blocking meaning I cannot run anything else after discord starts, which is kinda problematic given slack listener would likey be the same, someone showed me and example last night of how to do it using task and get.event.loop but that is depreciated and will not work in the future
There's a workaround for that
You need to create your own event loop and store it
However, Pycord already does this for you
Huh, the issue is as is the code is blocking, how would I get pycord to make me an event loop. Sorry if I’m asking so much lol
Nah it's okay
In asyncio, new_event_loop (which does exactly what you think it does) is not deprecated
So Pycord uses that unless you provide your own event loop
You can grab it via this attribute: https://docs.pycord.dev/en/master/api.html?highlight=client#discord.Client.loop
ah. async.io.get_event_loop is apparently
that's what I was instally refering too
Yeah
loop = asyncio.new_event_loop()
loop.create_task(myTask())
loop.create_task(taskw())
loop.create_task(bot.start(keys.discord_token))
loop.create_task(finaltask())
loop.run_forever()
so is this what you were meaning
this works and seems to do everything I needed it to do
just wondering if it's the cleanest way of doing things
Yeah
One idea to clean it up is to instead loop through each task you want to make
For example: ```python
for task in (myTask(), myTaskTwo(), myEpicTask(), lmaoMyTask(), bot.start("my cool epic token")):
loop.create_task(task)
ah makes sense