#Is there any example of a bot that uses bot.start(token) instad of bot.run

1 messages · Page 1 of 1 (latest)

tardy nova
#

I would like this since I want to be able to put the client into a task since I am building a bridge between discord and other services and need to open other listeners using an async task

neon bronze
#

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

tardy nova
#

Thank you

#

I will test it

neon bronze
tardy nova
# neon bronze 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

neon bronze
#

I think so, but I'm not positive

tardy nova
#

I will test just hadn’t gotten around to test

#

Thank you very much though

neon bronze
#

You’re welcome

tardy nova
#

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

neon bronze
#

There's a workaround for that

#

You need to create your own event loop and store it

#

However, Pycord already does this for you

tardy nova
neon bronze
#

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

tardy nova
#

that's what I was instally refering too

neon bronze
#

Yeah

tardy nova
#

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

neon bronze
neon bronze
tardy nova
#

ah makes sense