A
A
Alex_nester6662022-03-30 09:49:41
Bots
Alex_nester666, 2022-03-30 09:49:41

How to run multiple copies of telegram bots with different tokens?

How to run multiple copies of telegram bots with different tokens?
Example code on aiogram. There is an example on the webhook, but this option does not suit me.

bot = Bot(token=config.BOT_TOKEN, parse_mode=types.ParseMode.HTML)
dp = Dispatcher(bot, storage=MemoryStorage())
async def on_startup(dp):
    filters.setup(dp)
    middlewares.setup(dp)

    await set_default_commands(dp)



if __name__ == "__main__":
    create_bdx()

    executor.start_polling(dp, on_startup=on_startup)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
D
Danil Gorev, 2022-03-30
@ketovv

If the option with webhooks is not suitable at all (there is an example here ), then there are several possible options:
1) Run several Docker containers with different environments, and pass the token as the TELEGRAM_TOKEN environment variable;
2) Run bots in separate threads ( threading module ), with the ability to synchronize if necessary.
3) Write your own Event Loop on asyncio, in which you can access the cart API using different tokens and request updates.
How many possibilities!

M
Michael, 2022-03-30
@Aveyloff

You run the file many times with different bot tokens

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question