Answer the question
In order to leave comments, you need to log in
How to make a variable from the user's text in telegrams?
import telebot
import pyautogui
import time
bot = telebot.TeleBot('')
TOKEN = ''
tb = telebot.TeleBot(TOKEN)
keyboard1 = telebot.types.ReplyKeyboardMarkup()
keyboard1.row('Хром', 'Скрин', 'НеСпящий')
keyboard1.row('Искать', 'Написать')
@bot.message_handler(commands=['start'])
def start_message(message):
bot.send_message(message.chat.id, 'Начнём', reply_markup=keyboard1)
@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text.lower() == 'хром':
pyautogui.moveTo(464, 1064, 1)
pyautogui.click()
time.sleep(3)
pyautogui.screenshot('my_screenshot.png')
photo = open('my_screenshot.png', 'rb')
tb.send_photo(message.chat.id, photo)
elif message.text.lower() == 'скрин':
pyautogui.screenshot('my_screenshot.png')
photo = open('my_screenshot.png', 'rb')
tb.send_photo(message.chat.id, photo)
elif message.text.lower() == 'неспящий':
pyautogui.moveTo(500, 500, 1)
pyautogui.moveTo(1, 1, 1)
elif message.text.lower() == 'искать':
pyautogui.hotkey('ctrl', 't')
time.sleep(3)
pyautogui.screenshot('my_screenshot.png')
photo = open('my_screenshot.png', 'rb')
tb.send_photo(message.chat.id, photo)
elif message.text.lower() == 'написать':
message = bot.send_message(message.chat.id, 'Введите текст')
bot.send_message(message.chat.id, message)
bot.polling()
elif message.text.lower() == 'написать':
message = bot.send_message(message.chat.id, 'Введите текст')
bot.send_message(message.chat.id, message)
Answer the question
In order to leave comments, you need to log in
@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text.lower() == 'хром':
pyautogui.moveTo(464, 1064, 1)
pyautogui.click()
time.sleep(3)
pyautogui.screenshot('my_screenshot.png')
photo = open('my_screenshot.png', 'rb')
tb.send_photo(message.chat.id, photo)
elif message.text.lower() == 'скрин':
pyautogui.screenshot('my_screenshot.png')
photo = open('my_screenshot.png', 'rb')
tb.send_photo(message.chat.id, photo)
elif message.text.lower() == 'неспящий':
pyautogui.moveTo(500, 500, 1)
pyautogui.moveTo(1, 1, 1)
elif message.text.lower() == 'искать':
pyautogui.hotkey('ctrl', 't')
time.sleep(3)
pyautogui.screenshot('my_screenshot.png')
photo = open('my_screenshot.png', 'rb')
tb.send_photo(message.chat.id, photo)
elif message.text.lower() == 'написать':
message = bot.send_message(message.chat.id, 'Введите текст')
bot.register_next_step_handler(message, msg_0)
def msg_0(message):
msg=message.text
bot.send_message(message.chat.id, message)
bot.register_next_step_handler(message, send_text)
bot.polling()
elif message.text.lower() == 'написать':
msg = bot.send_message(message.chat.id, 'Введите текст')
bot.register_next_step_handler(msg, process_step)
bot.clear_step_handler(msg)
@bot.message_handler(content_types=['text'])
def process_step(message):
bot.send_message(message.chat.id, message.text)
Judging by the logic, you want to be able to get the text requested after "Enter text"?
Then you need to use register_next_step_handler . The following function is written in it, which already accepts text input.
bot.send_message(message.chat.id, 'Введите текст')
bot.register_next_step_handler(message, get_text)
def get_text(message):
message.text будет как раз запрашиваемый текст
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question