0

Hey i am trying to run a telegram bot on a daily base so i tried different things.

updater = Updater(<botkey>, use_context=True)
dp = updater.dispatcher
dp.job_queue.run_daily(pollen, datetime.time(hour=20, minute=9), days=(0, 1, 2, 3, 4, 5, 6))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()

def pollen(update, context):
    bot.send_message(chat_id=chat_id, text='text')

or

updater = Updater(<botkey>, use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', creatJobs, pass_job_queue=True, pass_chat_data=True))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()

def pollen(update, context):
    bot.send_message(chat_id=chat_id, text='text')


def creatJobs(update, context):
    new_job = context.job_queue.run_daily(pollen, datetime.time(hour=20, minute=9), days=(0, 1, 2, 3, 4, 5, 6), context=chat_id)
    context.chat_data['job'] = new_job

or

updater = Updater(<botkey>, use_context=True)
dp = updater.dispatcher
dp.add_handler(CommandHandler('start', creatJobs, pass_job_queue=True, pass_chat_data=True))
dp.add_error_handler(error)
updater.start_polling()
updater.idle()

def pollen(update, context):
    bot.send_message(chat_id=chat_id, text='text')

def creatJobs(update, context):
    context.job_queue.run_daily(reset, pollreset, days=(0,1,2,3,4,5,6))

but nothing works, i am developing on windows and python 3.8 imports always the same

import logging, re, datetime, time

import telegram
from telegram import InlineKeyboardButton, InlineKeyboardMarkup, Location
from telegram.ext import (Updater, CommandHandler, MessageHandler, Filters, ConversationHandler, CallbackQueryHandler)
MrTilllus
  • 328
  • 2
  • 5
  • 17
  • Please describe the issue you are having/error you're receiving – Hack5 Jun 09 '20 at 18:32
  • @Hack5 thats also a problem i am reciving no error or somthing else its just not working. I put all days in the tupel of run daily and the current time and then happens nothing – MrTilllus Jun 09 '20 at 18:36
  • 1
    Does this answer your question? [Python Telegram Bot - run\_daily does not work](https://stackoverflow.com/questions/61884051/python-telegram-bot-run-daily-does-not-work) – warren Jun 10 '20 at 17:16

1 Answers1

1

Due to a bug click here Job_queue is skipping job if timezone is not provided for job.run_daily.

Add timezone in your code it will run perfectly.

datetime.time(hour=6, minute=27, tzinfo=pytz.timezone('Asia/Kolkata'))

Refer the below code if you get any error.

from telegram.ext import Updater, CommandHandler
import logging, datetime, pytz

logging.basicConfig(level=logging.INFO,
                    format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
logger = logging.getLogger()


def start(update, context):
    context.job_queue.run_daily(msg,
                                datetime.time(hour=6, minute=27, tzinfo=pytz.timezone('Asia/Kolkata')),
                                days=(0, 1, 2, 3, 4, 5, 6), context=update.message.chat_id)

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

def error(update, context):
    """Log Errors caused by Updates."""
    logger.warning('Update "%s" caused error "%s"', update, context.error)


def main():
    updater = Updater( < YOUR_TOKEN > , use_context=True)
    dp = updater.dispatcher
    dp.add_handler(CommandHandler("start", start, pass_job_queue=True))
    dp.add_error_handler(error)

    updater.start_polling()
    updater.idle()

if __name__ == '__main__':
    main()
Siva Kumar
  • 133
  • 1
  • 8