【发布时间】:2018-06-25 13:37:20
【问题描述】:
您好,我想在特定时间从机器人发送消息(没有我的消息),例如每个星期六早上 8:00。 这是我的代码:
import telebot
import config
from datetime import time, date, datetime
bot = telebot.TeleBot(config.bot_token)
chat_id=config.my_id
@bot.message_handler(commands=['start', 'help'])
def print_hi(message):
bot.send_message(message.chat.id, 'Hi!')
@bot.message_handler(func=lambda message: False) #cause there is no message
def saturday_message():
now = datetime.now()
if (now.date().weekday() == 5) and (now.time() == time(8,0)):
bot.send_message(chat_id, 'Wake up!')
bot.polling(none_stop=True)
但这不起作用。 尝试过
urlopen("https://api.telegram.org/bot" +bot_id+ "/sendMessage?chat_id=" +chat_id+ "&text="+msg)
但还是没有结果。不知道怎么办,请帮忙指点一下。
【问题讨论】:
-
问题出在哪里?是时机还是你的机器人根本没有发送任何东西?
-
机器人不发送消息
-
没有你的日期检查是否可以工作?
-
不,只是不知道如何在这里制作循环(如何定期检查条件)
-
我有同样的问题,但在 C# stackoverflow.com/questions/64918790/…
标签: python python-3.x telegram telegram-bot