Amir Mfd
Amir Mfd

Reputation: 11

Telegram bot- how to send messages Daily

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()

Upvotes: 1

Views: 2950

Answers (1)

Yasser Sebai
Yasser Sebai

Reputation: 260

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)

Upvotes: 3

Related Questions