H
H
h1r0ku2020-04-27 14:50:32
Bots
h1r0ku, 2020-04-27 14:50:32

Telegram bot how can I implement it?

I want to make sure that in the first 3 games, if the user selects the buttons in the sequence (3,1,2), he wins, and in the next games, the winning buttons are random.

The code:

import telebot,config

bot = telebot.TeleBot(config.token)

@bot.message_handler(commands=['start'])
def start_message(message):
  msg = bot.send_message(message.from_user.id, 'Напишите сумму ставки.\nВ случае победы ваша ставка <b>утраивается!</b>', parse_mode="HTML")
  bot.register_next_step_handler(msg, enough_stavka)

def enough_stavka(message):
  global stavka
  game_markup = telebot.types.InlineKeyboardMarkup()
  first = telebot.types.InlineKeyboardButton('1⃣', callback_data='first')
  second = telebot.types.InlineKeyboardButton('2⃣', callback_data='second')
  three = telebot.types.InlineKeyboardButton('3⃣', callback_data='three')
  game_markup.row(first,second,three)
  stavka = int(message.text)
  if stavka < 1:
    msg = bot.send_message(message.from_user.id, "Сумма не может быть меньше 1 руб!")
    bot.register_next_step_handler(msg, enough_stavka)
  elif stavka >= 1:
    msg = bot.send_message(message.from_user.id, 'Выберити число:', reply_markup=game_markup, parse_mode="HTML")
    bot.register_next_step_handler(msg, game)

def game(call):
  bot.clear_step_handler_by_chat_id(call.from_user.id)
  again_markup = telebot.types.InlineKeyboardMarkup()
  again = telebot.types.InlineKeyboardButton('Играть ещё', callback_data='again')
  again_markup.row(again)
  if call.data == 'three':
    bot.send_message(call.from_user.id, 'Вы победили! Ваш выигрыш' + str(stavka * 3), reply_markup='again_markup')


if __name__ == '__main__':
  bot.polling()

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Lee, 2020-04-27
@appliks

I don’t know the capabilities of telegrams api well, but I think it doesn’t save this data (the maximum you can change buttons sequentially depending on the previous button), so use the database (where its commands will be saved).

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question