telegram.ext.Job

class telegram.ext.Job(callback, interval=None, repeat=True, context=None, days=(0, 1, 2, 3, 4, 5, 6), name=None, job_queue=None, tzinfo=datetime.timezone.utc)

Bases: object

This class encapsulates a Job.

callback

The callback function that should be executed by the new job.

Type:callable
context

Optional. Additional data needed for the callback function.

Type:object
name

Optional. The name of the new job.

Type:str
Parameters:
  • callback (callable) –

    The callback function that should be executed by the new job. Callback signature for context based API:

    def callback(CallbackContext)

    a context.job is the telegram.ext.Job instance. It can be used to access its job.context or change it to a repeating job.

  • interval (int | float | datetime.timedelta, optional) – The time interval between executions of the job. If it is an int or a float, it will be interpreted as seconds. If you don’t set this value, you must set repeat to False and specify time_spec when you put the job into the job queue.
  • repeat (bool, optional) – If this job should be periodically execute its callback function (True) or only once (False). Defaults to True.
  • context (object, optional) – Additional data needed for the callback function. Can be accessed through job.context in the callback. Defaults to None.
  • name (str, optional) – The name of the new job. Defaults to callback.__name__.
  • days (Tuple[int], optional) – Defines on which days of the week the job should run. Defaults to Days.EVERY_DAY
  • job_queue (telegram.ext.JobQueue, optional) – The JobQueue this job belongs to. Only optional for backward compatibility with JobQueue.put().
  • tzinfo (datetime.tzinfo, optional) – timezone associated to this job. Used when checking the day of the week to determine whether a job should run (only relevant when days is not Days.EVERY_DAY). Defaults to UTC.
days

Optional. Defines on which days of the week the job should run.

Type:Tuple[int]
enabled

Whether this job is enabled.

Type:bool
interval

Optional. The interval in which the job will run.

Type:int | float | datetime.timedelta
interval_seconds

The interval for this job in seconds.

Type:int
job_queue

Optional. The JobQueue this job belongs to.

Type:telegram.ext.JobQueue
removed

Whether this job is due to be removed.

Type:bool
repeat

Optional. If this job should periodically execute its callback function.

Type:bool
run(dispatcher)

Executes the callback function.

schedule_removal()

Schedules this job for removal from the JobQueue. It will be removed without executing its callback function again.