如何解决pyTelegramBotAPItelebot通过/ stop命令从while退出
我写了一个机器人,用于通过以下命令检查snmp上的负载均值:snmpwalk -v3 -l authNoPriv -u admin -a SHA -A“ admin”'+服务器+'.1.3.6.1.4.1.2021.10.1.3 .1。
我无法通过stop命令退出while循环。
bot = telebot.TeleBot('xxxxx')
@bot.message_handler(commands=['start'])
def start(message):
sent = bot.send_message(message.chat.id,'Please input server (example 192.168.0.1)')
bot.register_next_step_handler(sent,cores)
def cores(message):
global server
server = (message.text)
sent2 = bot.send_message(message.chat.id,'Input number of cores')
bot.register_next_step_handler(sent2,botstarted)
def botstarted(message):
global core
global bye
core = (message.text)
cores = float(core)
bot.send_message(message.chat.id,'Check started,if load average more then number of cores you get Warning message to stop enter /stop')
while (True):
b = os.popen('snmpwalk -v3 -l authNoPriv -u admin -a SHA -A "admin" ' + server + ' .1.3.6.1.4.1.2021.10.1.3.1').read()
d = (b[39:43])
c = float(b[39:43])
if c > cores:
bot.send_message(message.chat.id,'Warning,huge load average: ' + d)
print(c)
time.sleep(10)
@bot.message_handler(commands=['stop'])
def stop(message):
sent3 = bot.send_message(message.chat.id,'bye')
print(sent3)
bot.polling(none_stop=True)
解决方法
bot.stop_polling() but this = exit
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。