I have telegram bot which is made by python. The file must run at 06:00 P.M everyday. My PC is Windows 10. How can I achieve this , please guide me.
Asked
Active
Viewed 1,221 times
3 Answers
1
You can use Windows scheduled tasks:
Save your python file. For example: my_python.py
Create a bat file that runs my_python.py. Assuming Python is installed in the path below:
"C:\Users\MyUser\AppData\Local\Programs\Python\Python37-32\python.exe"
And my_python is saved in:
"C:\Users\MyUser\Desktop\my_python.py"
Create new text file and save it as run_my_python.bat with the following content:
"C:\Users\MyUser\AppData\Local\Programs\Python\Python37-32\python.exe" "C:\Users\MyUser\Desktop\my_python.py"
- Create a scheduled task to run run_my_python.bat. Go to Windows Task Scheduler, set your trigger, and choose "Start a program" action. Select run_my_python and save the scheduled task.

Yoav Sheetrit
- 149
- 9
0
- Find out your Python exe path, e.g., C:\python-path\python.exe
- Save your Python script somewhere and note the path
- Then, open the Task Scheduler
- Go to Actions > Create Task
- Give it a name and then Go to Actions > New
- Ensure the action is 'Start a program'
- In the "Program/script" you will add the path of the Python exe (C:\python-path\python.exe).
- In the "Add arguments (optional)” box, you will add the name of your python file (e.g., myScript.py).
- In the "Start in (optional)" box, you will add the location of your Python file (the whole path of the file, C:\path-to-the-python-script).
-
A link to a solution is welcome, but please ensure your answer is useful without it: add context around the link so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. Answers that are little more than a link may be deleted. – Zahra Dec 07 '21 at 08:59
0
If you are using python-telegram-bot
you should take a look at JobQueue.
It has a run_daily
which does what you want:
run_daily(callback, time, days=(0, 1, 2, 3, 4, 5, 6), context=None, name=None)
Here is an example with it:
def daily_function(context: telegram.ext.CallbackContext):
bot.send_message(chat_id=id, text='Daily message')
def call_daily_message(update,context):
context.job_queue.run_daily(daily_function, context=update.message.chat_id,days=(0, 1, 2, 3, 4, 5, 6),time = time(hour = 18, minute = 0, second = 0))
This example executes the function daily_function
everyday at 18:00.

Shunya
- 2,344
- 4
- 16
- 28