G
G
GRPUI2020-11-04 08:48:08
Python
GRPUI, 2020-11-04 08:48:08

How to make the bot process the messages of the user who called his command and ignore the messages of other users of the group?

It is necessary that the bot works with the user who wrote "! create a clan" and ignores the messages of other users in the group

import telebot
from telebot import types
from telebot import TeleBot

bot: TeleBot = telebot.TeleBot('токен')

clan_names = []

@bot.message_handler(content_types=['text'])
def get_text_messages(message):
    print(message.text)
    chat_id = message.chat.id
    if message.text == '!создать клан':
        if len(clan_names) < 6:
            chat_id = message.chat.id
            bot.send_message(message.chat.id, 'Назовите клан:', reply_to_message_id=message.message_id)
            bot.register_next_step_handler_by_chat_id(chat_id, get_name)
        elif len(clan_names) == 6:
            bot.send_message(message.chat.id, 'К сожалению, все слоты кланов заняты',
                             reply_to_message_id=message.message_id)

def get_name(message):
    chat_id1 = message.chat.id
    new_name = message.text
    bot.send_message(message.chat.id, new_name + ' - верное название?', reply_to_message_id=message.message_id)
    clan_names.append(new_name)
    print(clan_names)
    bot.register_next_step_handler_by_chat_id(chat_id1, accept)

def accept(message):
        if message.text == 'Да' or message.text == 'да':
            if len(clan_names) == 1:
                bot.send_message(message.chat.id, 'Клан ' + clan_names[0] + ' - успешно создан',
                                 reply_to_message_id=message.message_id)
                btn_1 = types.KeyboardButton(clan_names[0])
                markup_menu_1.add(btn_1)
            elif len(clan_names) == 2:
                bot.send_message(message.chat.id, 'Клан ' + clan_names[1] + ' - успешно создан',
                                 reply_to_message_id=message.message_id)
                btn_2 = types.KeyboardButton(clan_names[1])
                markup_menu_1.add(btn_2)
            elif len(clan_names) == 3:
                bot.send_message(message.chat.id, 'Клан ' + clan_names[2] + ' - успешно создан',
                                 reply_to_message_id=message.message_id)
                btn_3 = types.KeyboardButton(clan_names[2])
                markup_menu_1.add(btn_3)
            elif len(clan_names) == 4:
                bot.send_message(message.chat.id, 'Клан ' + clan_names[3] + ' - успешно создан',
                                 reply_to_message_id=message.message_id)
                btn_4 = types.KeyboardButton(clan_names[3])
                markup_menu_1.add(btn_4)
            elif len(clan_names) == 5:
                bot.send_message(message.chat.id, 'Клан ' + clan_names[4] + ' - успешно создан',
                                 reply_to_message_id=message.message_id)
                btn_5 = types.KeyboardButton(clan_names[4])
                markup_menu_1.add(btn_5)
            elif len(clan_names) == 6:
                bot.send_message(message.chat.id, 'Клан ' + clan_names[5] + ' - успешно создан',
                                 reply_to_message_id=message.message_id)
                btn_6 = types.KeyboardButton(clan_names[5])
                markup_menu_1.add(btn_6)
            idk.remove(message.from_user.id)
            print(idk)
            bot.register_next_step_handler_by_chat_id(chid, get_text_messages)

        elif message.text == 'Нет' or message.text == 'нет':
                if len(clan_names) == 1:
                    clan_names.remove(clan_names[0])
                    bot.send_message(message.chat.id, 'Начните с начала', reply_to_message_id=message.message_id)
                elif len(clan_names) == 2:
                    clan_names.remove(clan_names[1])
                    bot.send_message(message.chat.id, 'Начните с начала', reply_to_message_id=message.message_id)
                elif len(clan_names) == 3:
                    clan_names.remove(clan_names[2])
                    bot.send_message(message.chat.id, 'Начните с начала', reply_to_message_id=message.message_id)
                elif len(clan_names) == 4:
                    clan_names.remove(clan_names[3])
                    bot.send_message(message.chat.id, 'Начните с начала', reply_to_message_id=message.message_id)
                elif len(clan_names) == 5:
                    clan_names.remove(clan_names[4])
                    bot.send_message(message.chat.id, 'Начните с начала', reply_to_message_id=message.message_id)
                elif len(clan_names) == 6:
                    clan_names.remove(clan_names[5])
                    bot.send_message(message.chat.id, 'Начните с начала', reply_to_message_id=message.message_id)
            bot.register_next_step_handler_by_chat_id(chid, get_text_messages)

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question