【发布时间】:2017-11-08 20:46:06
【问题描述】:
import telebot
import requests
from telebot import types
import time
from datetime import datetime, date, time, timedelta
import schedule
pole = False
TOKEN = '*******BOT TOKEN***********'
bot = telebot.TeleBot(TOKEN)
def job():
pole=True
if pole == True:
bot.send_message(chat_id,'poleadaaaaa')
schedule.every(10).minutes.do(job)
schedule.every().hour.do(job)
schedule.every().day.at("21:24").do(job)
while 1:
schedule.run_pending()
time.sleep(1)
def listener(messages):
for m in messages:
if m.content_type == 'text':
cid = m.chat.id
print ("[" + str(cid) + "]: " + m.text)
bot.set_update_listener(listener)
@bot.message_handler(commands=['start'])
bot.send_message(chat_id, 'Hello you start the bot')
bot.polling(none_stop=True)
如果我输入以下代码,机器人不会回答 /start 命令和任何文本
def job():
pole=True
if pole == True:
bot.send_message(chat_id,'poleadaaaaa')
schedule.every(10).minutes.do(job)
schedule.every().hour.do(job)
schedule.every().day.at("21:24").do(job)
while 1:
schedule.run_pending()
time.sleep(1)
我不知道如果我输入此代码,我的机器人为什么不回答,因为如果没有此代码,它可以完美运行,并且在任何情况下都能立即回答。我将代码放在def listener(messages): 之前/之后和@bot.message_handler(commands=['start']) 内部,但机器人没有响应。
【问题讨论】:
标签: python-3.x telegram-bot schedule python-telegram-bot