S
S
serhiops2022-02-23 12:15:19
Python
serhiops, 2022-02-23 12:15:19

How to make it so that a message is sent from the telegram bot at a certain time?

I am using aiogram. You need to make sure that the message is sent at a certain time every day. How can this be implemented?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2022-02-23
@Vindicar

aioschedule

K
Kai41k, 2022-02-23
@Kai41k

It's done like this

import time
from datetime import datetime

time = datetime(datetime.now().year, datetime.now().month, datetime.now().day, datetime.now().hour, datetime.now().minute)

if time.hour == <час> and time.minute == <минут>:
  await bot.send_message(message.from_user.id, f'Время: {time.hour}:{time.minute}')
else:
  await bot.send_message(message.from_user.id, time)

Where in <hour> and <minutes> you need to specify the hour and minute at which the bot will send a message

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question