Run a code for two telegram bots

1.7k views Asked by At

I want to enter two tokens in a code, that is, by executing the code, two telegram bots will work.My codes:

from telegram.ext import Updater,CommandHandler
updater = Updater(token='TOKEN', token1='TOKEN1')

def start_method(bot,update):
    bot.sendMessage(update.message.chat_id,"Hello")
start_command = CommandHandler('start', start_method)
updater.dispatcher.add_handler(start_command)
updater.start_polling()

When I Run these code, it will error:

Traceback (most recent call last):
  File "G:/python2.7.9/dsdad.py", line 2, in <module>
    updater = Updater(token='TOKEN', token1='TOKEN1')
TypeError: __init__() got an unexpected keyword argument 'token1'

How can I do this?So that by inserting two tokens into the codes, the codes will run for both telegram bots ??

1

There are 1 answers

0
matsbauer On

You could do so by simply adding the bot code you want to use into the function. Than you can pass the two bots using threads into the function.

from threading import Thread

and then you place the threads as so, with xxxxxxxx being your bot code:

Thread(target=start_method, args=(xxxxxxxxx, )).start()