电报机器人在给定时间发布消息

时间:2018-08-07 15:04:23

标签: python telegram telegram-bot python-telegram-bot

我编写了以下代码以在一天中的某些时间发送消息。有人可以建议替代方法,这样我就不必保持系统运行?

import telebot
import datetime

bot_token = "(Insert your API Key here)"
bot = telebot.TeleBot(token=bot_token)
text = """
<Welcome Texts for Group Members>
"""
times = [3,14]
chat_id = bot.get_chat('@testgroup').id
while 1:
    current_time=datetime.datetime.now()
    hour = current_time.hour
    minute = current_time.minute
    second = current_time.second
    microsecond = current_time.microsecond
    if((hour in times) and (minute==0) and (second==0) and (microsecond==0)):
         bot.send_message(chat_id,text)

0 个答案:

没有答案