I'm having trouble adding command handlers on the run, here's an example:
from telegram.ext import Updater, CommandHandler
updater = Updater(token)
items = [
('a', 1),
('b', 2),
('c', 3)
]
for i in range(len(items)):
def dummy_func(bot, update):
print(items[i][1])
updater.dispatcher.add_handler(
CommandHandler(items[i][0], dummy_func)
)
updater.start_polling()
I would expect /a
to print 1
in my console for example, but instead 3
is printed for a, b or c. I thought maybe the function is stored every time in the same spot in memory and tried storing the callbacks in a list but it didn't help.
Any ideas on how to do this?