Answer the question
In order to leave comments, you need to log in
How to run code at specific date and time?
There is a date in unixtime when to run
import datetime
timestamp = 1339521878
import logging
import asyncio
from datetime import datetime
from aiogram import Bot, Dispatcher, executor, types
# Initalialization API token for work with Telegram Bot
API_TOKEN = "BOT TOKEN HERE"
# Configure logging
logging.basicConfig(level=logging.INFO)
# Initialize bot and dispatcher
bot = Bot(token=API_TOKEN)
dp = Dispatcher(bot)
@dp.message_handler()
async def echo(message: types.Message):
await message.answer(message.text)
async def scheduled(wait_for):
while True:
await asyncio.sleep(wait_for)
print('Время пришло!')
if __name__ == '__main__':
loop = asyncio.get_event_loop()
loop.create_task(scheduled(10)) # поставим 10 секунд, в качестве теста
executor.start_polling(dp, skip_updates=True)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question