D
D
Daniel_unknown2021-10-06 17:52:41
Python
Daniel_unknown, 2021-10-06 17:52:41

Working with telebot. How to fix?

I decided to try to write a bot, I wanted to add the /Game command, in which the bot sends a list of colors and prompts the user to select one of them. The user chooses and if it matches what random_color randomized, then the bot sends a message that the user guessed right or wrong. But after the user writes the /Game command, the bot accepts it as the selected color and sends a message that the user did not guess correctly.

import pyowm
import random2
import telebot
from time import sleep
from random import choice




@bot.message_handler(commands =['Game'] )
def game(message):
    bot.send_message(message.chat.id, "Введите ваш цвет(список:Зеленый Желтый Красный Синий)")
    colors = ['Желтый', 'Зеленый', 'Красный', 'Синий']
    random_color = (choice(colors)).lower()
    color_user = message.text.lower()
    if color_user == random_color:
        bot.send_message(message.chat.id, 'Ты угадал!Цвет был ' + random_color)
    else:
        bot.send_message(message.chat.id,'Ты не угадал!Цвет был ' + random_color)

Answer the question

In order to leave comments, you need to log in

2 answer(s)
V
Vindicar, 2021-10-06
@Daniil_unknown

> color_user = message.text.lower()
message what do you think it refers to?
It refers to the message in which the command came.
If you need to implement a scenario in which the user sends multiple messages, deal with register_next_step_handler()

P
Python Newbie, 2021-10-06
@Levman5

Replied to this recently

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question