G
G
GRPUI2020-09-02 10:48:42
Python
GRPUI, 2020-09-02 10:48:42

What needs to be corrected in the code so that in the message “*text* is the correct name” instead of !create a clan, there is a user message?

The bot does not respond correctly to the next step

How should it be:
- !create a clan
- Name the clan:
- Uchiha
- Uchiha - correct name?

@bot.message_handler(content_types=['text'])
def get_text_messages(message):
    if message.text == ('!Создать Клан') or message.text == ('!Создать клан') or message.text == (
            '!создать клан') or message.text == ('!СОЗДАТЬ КЛАН'):
        chat_id = message.chat.id
        bot.send_message(message.chat.id, 'Назовите клан:',)
        bot.register_next_step_handler_by_chat_id(chat_id,get_text_messages,get_name(message))
    if message.text == ('!Вступить в Клан') or message.text == ('!вступить в клан') or message.text == (
            '!Вступить в клан') or message.text == ('!ВСТУПИТЬ В КЛАН'):
        chat_id1 = message.chat.id
        bot.send_message(message.chat.id, 'В какой клан хотите вступить?', reply_to_message_id=message.message_id, reply_markup=markup_menu_1)
        return (chat_id1)
    elif message.text == 'Что я умею❓':
        bot.send_message(message.from_user.id,
                         "Я умею назначать роли участникам группы, создавать кланы и организации, а также добавлять в них участников.")
    elif message.text == 'Как добавить бота в чат❓':
        bot.send_message(message.from_user.id,
                         'Для того чтобы подлючить бота к чату нужно:\nПредоставить права администратора в чате, остальное он сделает сам')
def get_name(message):
    cht_id = message.from_user.id
    new_name = message.text
    bot.send_message(message.chat.id, new_name + ' - верное название?')

5f4f4c50d851e439654118.jpeg

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
soremix, 2020-09-02
@GRPUI

one.

if message.text == ('!Создать Клан') or message.text == ('!Создать клан') or message.text == (
            '!создать клан') or message.text == ('!СОЗДАТЬ КЛАН'):

replaced by
if message.text.lower().startswith('!создать клан'):

2.
bot.register_next_step_handler_by_chat_id(chat_id,get_text_messages,get_name(message))

on the
bot.register_next_step_handler_by_chat_id(result, get_name)

F
ferrson, 2020-09-02
@Proffs

You can do it like this:
1. Change the ifs a little

if message.text.startwith('Создать клан'):
   . . .

2. In this ife, split the message into words:
if message.text.startwith('Создать клан'):
   mess_split = message.text.split() #разделится на слова.

3. And check for the third word:
if message.text.startwith('Создать клан'):
   mess_split = message.text.split()
   if mess_split.__len__ - 1 != 2:
    #сделать, что-то.

Hope it helped.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question