How to send scheduled message using telebot python

Question:

In telegram client you can send a scheduled message and select a time at which it will be sent. Is there a way to do that using python Telebot library and not keep the script running and checking time manually?

Asked By: kepper104

||

Answers:

You could use modules like apscheduler

example usage:

import telebot
from apscheduler.schedulers.blocking import BlockingScheduler

sched = BlockingScheduler()
bot = telebot.TeleBot('token')

def my_interval_job():
    bot.send_message("WARNERSTARK", "Goodmorning. its 6am!")
    ... # do more at 6 am
    

sched.add_job(my_interval_job, trigger="cron", hour=6)
sched.start()

The above example sends a message to user at 6 am.

Read More

Answered By: WarnerStark
Categories: questions Tags: ,
Answers are sorted by their score. The answer accepted by the question owner as the best is marked with
at the top-right corner.