Answer the question
In order to leave comments, you need to log in
How to make it so that the string is passed to another function (telebot)?
import telebot
import config
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(content_types = ["text"])
def messages_1(message):
bot.send_message(message.from_user.id, "Не матерись!")
def messages_2(message):
if message.text.upper() in config.lst_7:
bot.send_message(message.from_user.id, f"{config.lst_8[random.randint(0, len(config.lst_8) - 1)]}")
elif message.text.upper() in config.lst_9:
bot.send_message(message.from_user.id, f"{config.lst_10[random.randint(0, len(config.lst_10) - 1)]}")
else:
bot.register_next_step_handler(message, messages_1)
bot.polling(none_stop = True, interval = 0)
bot.register_next_step_handler(message, messages_1)
Answer the question
In order to leave comments, you need to log in
See examples of how register_next_step_handler
is used The function
called in register_next_step_handler does not need to be wrapped with a decorator.
If you want to pass any parameters to the called function, then you need to add them to the parameters when calling register_next_step_handler .
@bot.message_handler(content_types = ["text"])
def messages_1(message):
param1 = 4
param2 = 5
mes = bot.send_message(message.chat.id, 'Введите сообщение')
bot.register_next_step_handler(mes, foo, param1, param2)
def foo(message, param1, param2):
print(message.text, param1, param2)
# теперь после того как бот пришлет 'Введите сообщение' если отправить "текст сообщения", в консоли выдаст
# "текст сообщения 4 5"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question