【问题标题】:I don't know why my bot doesn't answer after this code in python telegram我不知道为什么我的机器人在 python 电报中的这段代码之后没有回答
【发布时间】: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


    【解决方案1】:

    而 1: ....

    在另一个线程中运行这部分。

    【讨论】:

      猜你喜欢
      • 2020-10-16
      • 1970-01-01
      • 2022-12-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-01-26
      • 1970-01-01
      相关资源
      最近更新 更多