S
S
Stepan Nikolaevich2020-05-28 21:01:44
Python
Stepan Nikolaevich, 2020-05-28 21:01:44

How to restart telegram bot?

Friends! I write a bot in telegram. I am using telebot library. Added keyboard for answers. I need the bot to restart when the button is clicked... Is it possible to do this? If yes, then just write a command, thanks in advance! Read the documentation. Something could not find a solution

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SuckMyPython, 2020-08-30
@SuckMyPython

import os #импортируем модуль "os"

@bot.message_handler(commands=["restart"]) #вызов по команде /restart; можно сделать и на кнопку
def restart(message):
  pid = str(os.getpid()) #получаем ProcessID запущенного бота
  restarter = open('restarter.bat', 'w') #открываем/создаем батник
  restarter.write('Taskkill /PID ' + pid + ' /F\nTIMEOUT /T 5 /NOBREAK\ncd C:\\Users\\smp\\Desktop\\SMP\\\nsmp.py') #записываем скрипт в батник		
  restarter.close() #закрываем отредактированный батник
  os.system('C:/Users/smp/Desktop/SMP/restarter.bat') #запускаем наш батник

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question