G
G
galaxy31412021-05-06 20:59:26
Python
galaxy3141, 2021-05-06 20:59:26

Hello, such a situation, a person who has a username, when you click on the / start button, a message and a button appear.?

a person who has a username when you click on the / start button, a message and a button appear. 60942e5f2aed9614444905.pngand who does not have a username, only a message appears without a button

@bot.message_handler(content_types=["text"])
def message_send(message):
  if '/start' == message.text:
    if message.chat.username:
      if message.chat.id in in_admin: in_admin.remove(message.chat.id)
      if message.chat.id == config.admin_id and dop.it_first(message.chat.id) is True: in_admin.append(message.chat.id)
      elif dop.it_first(message.chat.id) is True and message.chat.id not in dop.get_adminlist():
        bot.send_message(message.chat.id, 'Бот ещё не готов к работе!\nЕсли вы являетесь его администратором, то войдите из под аккаунту, id которого указали при запуске бота и подготовьте его к работе!')
      elif dop.check_message('start') is True:
        key = telebot.types.InlineKeyboardMarkup()
        key.add(telebot.types.InlineKeyboardButton(text='Перейти к каталогу товаров', callback_data='Перейти к каталогу товаров'))
        with shelve.open(files.bot_message_bd) as bd: start_message = bd['start']
        start_message = start_message.replace('name', message.from_user.first_name)
        bot.send_message(message.chat.id, start_message, reply_markup=key)	
      elif dop.check_message('start') is False and message.chat.id in dop.get_adminlist():
        bot.send_message(message.chat.id, 'Приветствие ещё не добавлено!\nЧтобы его добавить, перейдите в админку по команде /adm и *настройте ответы бота*', parse_mode='Markdown')

      dop.user_loger(chat_id=message.chat.id) #логгирование юзеровs
    elif not message.chat.username:
      with shelve.open(files.bot_message_bd) as bd: start_message = bd['userfalse']
      start_message = start_message.replace('uname', message.from_user.first_name)
      bot.send_message(message.chat.id, start_message, parse_mode='Markdown')


      dop.user_loger(chat_id=message.chat.id) #логгирование юзеровs
    elif not message.chat.username:
      with shelve.open(files.bot_message_bd) as bd: start_message = bd['userfalse']
      start_message = start_message.replace('uname', message.from_user.first_name)
      bot.send_message(message.chat.id, start_message, parse_mode='Markdown')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
J
Jourloy, 2021-05-08
@Jourloy

  1. You have a piece of code duplicated. Perhaps you, of course, inserted it like this
  2. Line 4 contains if message.chat.username:where it is clearly stated that if a person has a username, then display an answer to him with a button. You need to either remove the condition or change it

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question