V
V
Vitaliy4452021-09-22 17:00:40
Python
Vitaliy445, 2021-09-22 17:00:40

How to send a message to a user with a delay?

How to send message to user after n seconds (not time.sleep)?
I used telegram.ext.JobQueue (I found it somewhere on the Internet), but something does not work, the bot is silent I
took the information from here: https://github.com/python-telegram-bot/python-tele...
ps - I I don’t tolerate documentation without illustrative examples, so don’t judge strictly)

The code
@bot.message_handler(commands=['start'])
def welcome(message):
    bot.send_message(message.chat.id, ...)
    j.run_once(callback_1, 10)

def callback_1(context):  #На context: telegram.ext.CallbackContext компилятор ругается
    context.bot.send_message(chat_user_id, text='...')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Shitskov, 2021-09-22
@Zarom

from telegram.ext import Updater, CallbackContext


u = Updater(config.TOKEN, use_context=True)
j = u.job_queue

@bot.message_handler(commands=['start'])
def welcome(message):
    bot.send_message(message.chat.id, '...')
    j.run_once(callback_1, 10, context=message.chat.id)

def callback_1(context: CallbackContext):
    context.bot.send_message(chat_id=context.job.context, text='...')

Yes, according to the documentation

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question