Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question