D
D
Denis2020-11-13 23:09:39
Python
Denis, 2020-11-13 23:09:39

How to run 2 or more bots at the same time?

I decided to write Telegram bots interacting with each other in python.
I decided to use pyrogram for this, since one of the bots is a user account!
How to simultaneously run 2 or more bots in one program?

banal:
first_client.run()

second_client.run()
does not work

Tell me what to do

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
shurshur, 2020-11-14
@Demen1205

This is an asynchronous framework, you need to run separate tasks for clients. And run starts a task with this client and waits for it to complete, so the first client is launched, and the second one is not.
Accordingly, you need to do this:
first_client.start()
second_client.run()

N
nvlveu, 2020-11-13
@nvlveu

Read each bot's file and in a loop run:

from threading import Thread

target = lambda: exec(f'{code}', locals())
Thread(target=target).start()

Or via the command line:
start cmd /c py -3 "путь к файлу" && start cmd /c py -3 "путь к файлу"

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question