S
S
sm0zzy2021-02-22 21:48:51
Bots
sm0zzy, 2021-02-22 21:48:51

How to create a telegram bot that sends a message at a specific time?

The first bot in a telegram, what is the best way to write a script that will connect to a telegram phone number and from a certain time to a certain time will send the same message to all users
By type (working day is over)?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
Y
Yupiter7575, 2021-02-22
@yupiter7575

If you are writing in python, you can try using the time library, namely sleep(). You get something like this:

from time import sleep
...
while True:
    sleep(3600) #остановиться на час
    send_message()

M
MinTnt, 2021-02-23
@MinTnt

There were already similar questions
Use cron to organize . sleep() is not suitable, as it stops the entire script from running. Those. as soon as the program stumbles upon sleep(), it will wait until the specified time has passed, and other actions will become unavailable. Of course, there is an option to allocate to a thread, but then you may have to suffer a little, since you will have to kill all active threads at the end, since they will not end while there is a goal.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question