E
E
emperorman2021-10-03 21:35:53
Python
emperorman, 2021-10-03 21:35:53

Error in Python code, can't figure it out?

The code communicates with Linux

Created buttons A, B, C

Then I wrote down that I want button A to send the uptime command to the chat, for example, but the bot sends the command A and not uptime

Help the newbie figure it out)

from subprocess import check_output
import telebot
import time
from telebot import types

bot = telebot.TeleBot("7fYlqRvrWrsi0SXmqOlkGLQ")
user_id = 1985

@bot.message_handler(commands=['start'])
def start(message):
  markup = types.ReplyKeyboardMarkup()
  buttonA = types.KeyboardButton(text ='A', callback_data ='a')
  buttonB = types.KeyboardButton('B')
  buttonC = types.KeyboardButton('C')

  markup.row(buttonA, buttonB)
  markup.row(buttonC)

  bot.send_message(message.chat.id, 'It works!', reply_markup=markup)

@bot.callback_query_handler(func = lambda call: True)
def answer(call):
    if call.data == 'a':
    bot.send_message(message.chat.id, 'uptime')

@bot.message_handler(content_types=["text"])
def main(message):
   if (user_id == message.chat.id):
      try:
         bot.send_message(message.chat.id, check_output(comand, shell = True))
      except:
         bot.send_message(message.chat.id, "Invalid input")


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

1 answer(s)
S
Sergo Zar, 2021-10-03
@Sergomen

There is not enough indentation after if

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question