Перемешивание вопросов с определенными кнопками в Телеграм боте
Опять-же столкнулся с данной проблемой: хочу реализовать в телеграм боте систему перемешивания вопросов с определенными на них ответами, но у меня не получается.

import telebot
from telebot import types
import random
token = ''
bot = telebot.TeleBot(token)
spes = ["Сколько время", "Когда домой?"]
@bot.message_handler(commands = ['start'])
def start(message):
bot.send_message(message.chat.id, text = random.choice(spes))
@bot.message_handler(content_types = ['text'])
def rf(message):
if bot.message == "Сколько время":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
k1 = types.KeyboardButton('хз')
k2 = types.KeyboardButton('Тоже хз')
markup.add(k1, k2)
bot.send_message(message.chat.id, 'wergwergh', reply_markup=markup)
def rf1(message):
if message.text == 'хз':
bot.send_message(message.chat.id, "Ага")
elif message.text == 'Тоже хз':
bot.send_message(message.chat.id, "Да")
bot.polling()
Ответы (1 шт):
Автор решения: M141
→ Ссылка
Я протестировал Ваше решение. Вот возможное решение проблемы:
import telebot
from telebot import types
import random
token = ''
bot = telebot.TeleBot(token)
spes = ["Сколько время", "Когда домой?"]
@bot.message_handler(commands=['start'])
def start(message):
question = random.choice(spes)
bot.send_message(message.chat.id, text=question)
if question == "Сколько время":
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
k1 = types.KeyboardButton('хз')
k2 = types.KeyboardButton('Тоже хз')
markup.add(k1, k2)
bot.send_message(message.chat.id, 'wergwergh', reply_markup=markup)
@bot.message_handler(content_types=['text'])
def rf1(message):
if message.text == 'хз':
bot.send_message(message.chat.id, "Ага")
elif message.text == 'Тоже хз':
bot.send_message(message.chat.id, "Да")
bot.polling()
bot.message не существует для проверки, хоть и message.text таким образом не реализуешь. Поэтому слегка подправил общую структуру Вашего кода, без использования фукнции rf.
Успехов в Ваших проектах :)