'TelegramBot send a message to a group chat every day at mm:HH a clock but not on a Sunday
I have a problem. I want to send to a certian group chat every day at 06:00 a clock a message.
When I am calling my script it just send once a Hello and the other commands like \Greet does not work.
import os
import telebot
import requests
from telebot.async_telebot import AsyncTeleBot
import asyncio
import datetime
load_dotenv()
API_KEY = os.getenv('API_KEY')
#print(API_KEY)
bot = AsyncTeleBot(API_KEY)
@bot.message_handler(commands=['Greet'])
def greet(message):
bot.reply_to(message, "Hey! Hows it going?")
async def hello():
await bot.send_message(<chatid>, "Hello")
async def wait_until(dt):
# sleep until the specified datetime
now = datetime.datetime.now()
await asyncio.sleep(5)
async def run_at(dt, coro):
await wait_until(dt)
return await coro
loop = asyncio.get_event_loop()
# print hello ten years after this answer was written
loop.create_task(run_at(datetime.datetime(2028, 7, 11, 23, 36),
hello()))
loop.run_forever()
asyncio.run(bot.polling())
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
