How to use Jobqueue in Python-telegram-bot

2024/10/14 23:15:32

I have able to make a bot very easily by reading the docs but Jobqueue is not working as per it is written. The run_daily method uses a datetime.time object to send the message at a particular time but this code neither does its job of sending a message nor shows any errors. It just keeps running

    import datetimefrom telegram import botfrom telegram.ext import Updaterdef callback_minute(bot, job):bot.send_message(chat_id=475838704, text='PlEaSe wOrK!')def main():updater = Updater()bot = updater.botjob = updater.job_queuedispatcher = updater.dispatcherjob.run_daily(callback_minute, time=datetime.time(6,33,00))updater.start_polling()updater.idle()if __name__ == '__main__':main()
Answer

Maybe this would help:

from telegram.ext import Updater, CommandHandlerdef daily_job(bot, update, job_queue):""" Running on Mon, Tue, Wed, Thu, Fri = tuple(range(5)) """bot.send_message(chat_id=<YOUR CHAT ID>, text='Setting a daily notifications!')t = datetime.time(10, 00, 00, 000000)job_queue.run_daily(notify_assignees, t, days=tuple(range(5)), context=update)def notify_assignees(bot, job):bot.send_message(chat_id=<CHAT ID>, text="Some text!")updater = Updater(<BOT_TOKEN>)
updater.dispatcher.add_handler(CommandHandler('notify', daily_job, pass_job_queue=True))
updater.start_polling()

and say to bot /notify

https://en.xdnf.cn/q/69355.html

Related Q&A

Is there a way to override default assert in pytest (python)?

Id like to a log some information to a file/database every time assert is invoked. Is there a way to override assert or register some sort of callback function to do this, every time assert is invoked?…

How to install pycairo on osx?

I am trying to install the pycairo (Python bindings for the cairo graphics library) under OSX.I started witheasy_install pycairoand got: Requested cairo >= 1.8.8 but version of cairo is 1.0.4error: …

How do I change a value in a .npz file?

I want to change one value in an npz file.The npz file contains several npys, I want all but one ( run_param ) to remain unchanged and I want to save over the original file.This is my working code:DATA…

How to load *.hdr files using python

I would like to read an environment map in *.hdr file format. It seems that very popular libraries doesnt support .hdr file reading, for example, OpenCV, PIL etc.. So how to read a .hdr file into a num…

What is the preferred way to compose a set from multiple lists in Python

I have a few different lists that I want to turn into a set and use to find the difference from another set. Lets call them A, B, and C. Is the more optimal way to do this set(A + B + C) or set(A).unio…

matplotlib plot small image without resampling

Im trying to plot a small image in python using matplotlib and would like the displayed axes to have the same shape as the numpy array it was generated from, i.e. the data should not be resampled. In o…

Nullable ForeignKeys and deleting a referenced model instance

I have a ForeignKey which can be null in my model to model a loose coupling between the models. It looks somewhat like that:class Message(models.Model):sender = models.ForeignKey(User, null=True, blank…

UnrecognizedImageError - image insertion error - python-docx

I am trying to insert an wmf file to docx using python-docx which is producing the following traceback. Traceback (most recent call last):File "C:/Users/ADMIN/PycharmProjects/ppt-to-word/ppt_reade…

Python pool map and choosing number of processes

In setting the number of processes, Id be keen to see how many threads I can actually use on my machine - how do I find this? Is there a way to determine the number of threads available to me?

connection times out when trying to connect to mongodb atlas with python

Im trying to connect to my mongodb atlas cluster but i keep getting timed out as soon as i try to do something with my db. The db i use was created in mongoshell and also the collection i checked their…