TOKEN = 'token'
bot = telebot.TeleBot(TOKEN)
def main():
for i in range(0,100):
print(i)
@bot.message_handler(commands=['start'])
def start(message):
main()
@bot.message_handler(commands=['stop'])
def stopfunc(message):
#how to stop the function main() ?
while True:
bot.polling()
答案 0 :(得分:0)
添加停止标志:
stop = False
def main():
global stop
for i in range(0,100):
if stop:
break
print(i)
@bot.message_handler(commands=['stop'])
def stopfunc(message):
global stop
stop = True
...