Answer the question
In order to leave comments, you need to log in
How to create a reminder in telegram bot? Reminder every month?
Help make a bot that will send
a reminder message every month to every bot user.
That is:
- a reminder every month
- to all bot users
Answer the question
In order to leave comments, you need to log in
0. Put aiogram and read Quick start to understand how the bot will work in general.
1. Create and maintain a bot user base, for example, in sqlite3 . How to fill it, this is the second question. You may also need a separate table of reminders, but you know better what kind of reminders there will be.
2. In the bot, you create an endless task via asyncio.create_task() , which
- checks the time
- if now is the right time (say, noon, 1st of the month, plus or minus 30 seconds), calls the user notification coroutine,
- falls asleep for a minute with await asyncio.sleep() (never time.sleep()).
3. The user notification coroutine should extract from your database the notifications that need to be sent and the id of the users to whom these notifications need to be sent (see the sqlite3 docs on how to retrieve data from the database with a SELECT query). Then, for each user, it should send a text (see the aiogram docs) and handle a possible exception (for example, if the user has blocked the bot).
4. A couple of command handlers may be required to add/change reminder text.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question