Answer the question
In order to leave comments, you need to log in
Sending command to server on button click (telebot)?
Hello, there was a need to create a bot that could receive commands from the chat and report on the status of the server or execute commands, I implemented this feature, but in order not to constantly enter commands manually to restart nginx and Apache, I would like to implement buttons, but unfortunately and could not figure out how to assign commands to the buttons to the server.
tyfrom subprocess import check_output
import telebot
from telebot import types
import time
@bot.message_handler(content_types=["text"])
def main(message):
if (user_id == message.chat.id):
comand = message.text
markup = types.ReplyKeyboardMarkup()
markup.row('Start nginx', 'Stop nginx')
markup.row('Start Apache', 'Stop', 'Restart')
bot.send_message(message.chat.id, "Выбери вариант:", reply_markup=markup)
try:
bot.send_message(message.chat.id, check_output(comand, shell = True))
except:
bot.send_message(message.chat.id, "Ошибка ввода")
if __name__ == '__main__':
while True:
try:
bot.polling(none_stop=True)
except:
time.sleep(10)
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question