D
D
Dima2021-06-21 21:40:06
Python
Dima, 2021-06-21 21:40:06

How to make that the user can only register commands once in the approach?

import telebot
import random
import time

TOKEN = ('1вывыввы')
bot = telebot.TeleBot(TOKEN)


#текс
@bot.message_handler(content_types=['text'])
def text(message):
  if message.text == '/Привет':
    bot.send_message(message.chat.id, 'Привет, я бот Кеша давай поиграем с тобой!')
    time.sleep(1)
    bot.send_message(message.chat.id, 'С каким словом будем играть?')
    bot.send_message(message.chat.id, 'БУТЫЛКА, СКОВОРОДКА, ВОРОНА')
  if message.text == '/БУТЫЛКА':
    bot.send_message(message.chat.id, 'Беремь слово "БУТЫЛКА"')
    bot.send_message(message.chat.id, 'и давай на перегоньки, кто первый переделает это слово чтобы получилось новое слово!')
    time.sleep(3)
    bot.send_message(message.chat.id, '3')
    bot.send_message(message.chat.id, '2')
    bot.send_message(message.chat.id, '1')
  elif message.text == '/СКОВОРОДКА':
    bot.send_message(message.chat.id, 'Беремь слово "СКОВОРОДКА"')
    bot.send_message(message.chat.id, 'и давай на перегоньки, кто первый переделает это слово чтобы получилось новое слово!')
    time.sleep(3)
    bot.send_message(message.chat.id, '3')
    bot.send_message(message.chat.id, '2')
    bot.send_message(message.chat.id, '1')

  elif message.text == '/ВОРОНА':
    bot.send_message(message.chat.id, 'Беремь слово "ВОРОНА"')
    bot.send_message(message.chat.id, 'и давай на перегоньки, кто первый переделает это слово чтобы получилось новое слово!')
    time.sleep(3)
    bot.send_message(message.chat.id, '3')
    bot.send_message(message.chat.id, '2')
    bot.send_message(message.chat.id, '1')



  if message.text in ['/БУТЫЛЬ', '/БУТЫЛКИ']:
    bot.send_message(message.chat.id, "Отлично ты справился первее меня!")

bot.polling()


For example, a person will write / Hello once and a second time, how to make him be able to write hello a second time after the end of the game?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Mikhail Krostelev, 2021-06-21
@twistfire92

He can always write anything. The question is how will you handle it. You need to store the state of each user at the current moment somewhere in the database so that the answer is based on this data. And with the repeated message "Hello!" answer him like "Hey, we're not finished yet."
In general, it is better to implement this whole idea of ​​yours through inline buttons. This is easier to describe in the code and it will be more convenient for the user to interact with your bot.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question