Telegram bot- how to send messages Daily

纵然是瞬间 提交于 2020-06-28 09:53:36

问题


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

回答1:


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)


来源:https://stackoverflow.com/questions/61650938/telegram-bot-how-to-send-messages-daily

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!