telegram.ext.Job¶
- class telegram.ext.Job(callback, data=None, name=None, chat_id=None, user_id=None)[source]¶
Bases:
objectThis class is a convenience wrapper for the jobs held in a
telegram.ext.JobQueue. With the current backend APScheduler,jobholds aapscheduler.job.Jobinstance.Objects of this class are comparable in terms of equality. Two objects of this class are considered equal, if their
idis equal.Important
If you want to use this class, you must install PTB with the optional requirement
job-queue, i.e.pip install python-telegram-bot[job-queue]
Note
All attributes and instance methods of
jobare also directly available as attributes/methods of the correspondingtelegram.ext.Jobobject.Warning
This class should not be instantiated manually. Use the methods of
telegram.ext.JobQueueto schedule jobs.See also
Changed in version 20.0:
Removed argument and attribute
job_queue.Renamed
Job.contexttoJob.data.Removed argument
jobTo use this class, PTB must be installed via
pip install python-telegram-bot[job-queue].
- Parameters
callback (coroutine function) –
The callback function that should be executed by the new job. Callback signature:
async def callback(context: CallbackContext)
data (
object, optional) – Additional data needed for the callback function. Can be accessed throughJob.datain the callback. Defaults toNone.name (
str, optional) – The name of the new job. Defaults tocallback.__name__.Chat id of the chat that this job is associated with.
New in version 20.0.
User id of the user that this job is associated with.
New in version 20.0.
- chat_id[source]¶
Optional. Chat id of the chat that this job is associated with.
New in version 20.0.
- Type
- user_id[source]¶
Optional. User id of the user that this job is associated with.
New in version 20.0.
- Type
- property job[source]¶
The APS Job this job is a wrapper for.
Changed in version 20.0: This property is now read-only.
- Type
- property next_t[source]¶
Datetime for the next job execution. Datetime is localized according to
datetime.datetime.tzinfo. If job is removed or already ran it equals toNone.Warning
This attribute is only available, if the
telegram.ext.JobQueuethis job belongs to is already started. Otherwise APScheduler raises anAttributeError.- Type
- async run(application)[source]¶
Executes the callback function independently of the jobs schedule. Also calls
telegram.ext.Application.update_persistence().Changed in version 20.0: Calls
telegram.ext.Application.update_persistence().- Parameters
application (
telegram.ext.Application) – The application this job is associated with.