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