1

I am trying to develop a telegram-bot that send a message every day at a specific time. but it's not working for me. I think the problem is in the time parameter. I used another method of this class and they were working well but run_daily is not working. :(

import telegram.ext
from telegram.ext import Updater
from datetime import time

updater = Updater('My Token', use_context=True)
job = updater.job_queue

def callback_minute(context: telegram.ext.CallbackContext):
    context.bot.send_message(chat_id='My Chat ID', text='One message every minute')

# job.run_repeating(callback_minute, interval=5, first=0)
job.run_daily(callback_minute,time = time(hour = 20, minute = 2, second = 00),days=(0, 1, 2, 3, 4, 5, 6))

updater.start_polling()
updater.idle()
Amir Mfd
  • 11
  • 1
  • 2
  • do you run it all time (24h/7days) ? Usually job shedulers need loop which runs all time and it checks if it is time to run task. In documentation [telegram.ext.JobQueue](https://python-telegram-bot.readthedocs.io/en/stable/telegram.ext.jobqueue.html) I see [start()](https://python-telegram-bot.readthedocs.io/en/stable/telegram.ext.jobqueue.html#telegram.ext.JobQueue.start) to start the job_queue thread - maybe you have to use it. – furas May 07 '20 at 06:38
  • BTW: did you try to use Google to find some examples how to use this `run_daily()` ? Maybe it needs something more to run correctly - ie `job.start()`. – furas May 07 '20 at 06:40

1 Answers1

3

you're using the datetime object wrongly..

first of all, note that the datetime object you're creating will consider the UTC time and date unless you modify it..

as for your problem, modify your code to look like this, it's cleaner to you when you'll have a lot of times to deal with and it should solve the main problem:

import datetime
t = datetime.time(20, 2, 00, 000000)
job.run_daily(callback_minute,t,days=(0, 1, 2, 3, 4, 5, 6),context=None,name=None)
Yasser Sebai
  • 260
  • 2
  • 11