G
G
galaxy31412021-05-06 16:59:33
Python
galaxy3141, 2021-05-06 16:59:33

Hello, I am writing my bot, the bot sends a message only to those who have a username, who do not have it, they do not reach it.?

@bot.message_handler(content_types=["text"])
def message_send(message):
  if '/start' == message.text:
    if message.chat.username:
      if dop.get_sost(message.chat.id) is True: 
        with shelve.open(files.sost_bd) as bd: del bd[str(message.chat.id)]
      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('username', message.chat.username)
        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')

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2021-05-06
@SoreMix

Because you literally check for the presence of a username ( if message.chat.username:) and execute the code only if it exists.
Well, there is a special decorator for commands. To not eatif '/start' == message.text:@bot.message_handler(commands=["start"])

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question