D
D
DEUS92018-07-25 09:46:26
Python
DEUS9, 2018-07-25 09:46:26

How to pass chat parameters to telegram bot function, python-telegram-bot without Handler?

def bot():
    print("bot online")
    updater = Updater(token=Tokens.bot_token('live'))
    dispatcher = updater.dispatcher
    commands = Commands
    # job
    j = updater.job_queue
    j.run_repeating(InfoMessage.use_discounts, 15) #<---- Задание с задержкой в которое нужно передать параметры (chat_id)
    #commands
    start_handler = CommandHandler('start', commands.start)
    dispatcher.add_handler(start_handler)
    contact_handler = MessageHandler(Filters.contact, commands.contact)
    dispatcher.add_handler(contact_handler)
    updater.start_polling()

if __name__ == '__main__':
    bot()

class InfoMessage():
    def use_discounts(bot, update):
        print(update.message.chat_id)

How to get message.chat_id in the use_discounts method? The rest of the functions work through the Handler, it passes the parameters to bot, update. The use_discounts method must be called separately without commands (called through JobQueue) and that it would work after restarting the bot.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
B
be52, 2018-07-25
@DEUS9

update.message.chat_id is the number of the interlocutor, the function that is called according to the schedule does not and cannot have it,
but if you know someone's number, you can send him a message from this function
bot.send_message(chat_id=123456, text = '*wake up * Neo', parse_mode='Markdown')
j.run_repeating(func, 0)
def func(bot, job): <-- this should be job and not update

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question