M
M
Megach2020-06-10 17:15:28
Python
Megach, 2020-06-10 17:15:28

Why callback_data is not processed and the function is not called?

Hello, I would like to ask a question:
Why is the callback_data not processed and the function is not called? (if it only applies to my code)
Here is my code:

@bot.message_handler(content_types=['text'])
def mess(message):	

        elif message.text == "1":
        markup = types.InlineKeyboardMarkup(row_width=1)
  odin = types.InlineKeyboardButton("Готово", callback_data="odin")
        markup.add(odin)
  bot.send_message(message.chat.id, "Укажите свою настоящую Фамилию и Имя", reply_markup=markup)
        
@bot.callback_query_handler(func=lambda call: True)
def Inline_callback(call):
  try:
    if call.message:
        		if  call.data == "odin":
        if int(message.chat.id) == int(config.owner):
          try:
            chatId=message.text.split(': ')[0]
            text=message.text.split(': ')[1]
            bot.send_message(chatId, text)
          except:
            pass
        else:
          bot.send_message(config.owner, str(message.chat.id) + ': ' + message.text)
          bot.send_message(message.chat.id, '%s, wait please '%message.chat.username)


I need to make it so that
when you click on the inline done button call.data should work

Answer the question

In order to leave comments, you need to log in

2 answer(s)
T
Timur Pokrovsky, 2020-06-10
@Makaroshka007

elif message.text == "1":
elif without if

S
soremix, 2020-06-10
@SoreMix

@bot.message_handler(content_types=['text'])
def mess(message):	

        elif message.text == "1":
        markup = types.InlineKeyboardMarkup(row_width=1)
  odin = types.InlineKeyboardButton("Готово", callback_data="odin")
        markup.add(odin)
  bot.send_message(message.chat.id, "Укажите свою настоящую Фамилию и Имя", reply_markup=markup)

  1. Worth elif, where if?
  2. No indent after elif
  3. Even less indentation in the creation of the keyboard
  4. No padding in markup.add()
  5. bot.send_message

@bot.callback_query_handler(func=lambda call: True)
def Inline_callback(call):
  try:
    if call.message:
        		if  call.data == "odin":
        if int(message.chat.id) == int(config.owner):
          try:
            chatId=message.text.split(': ')[0]
            text=message.text.split(': ')[1]
            bot.send_message(chatId, text)
          except:
            pass
        else:
          bot.send_message(config.owner, str(message.chat.id) + ': ' + message.text)
          bot.send_message(message.chat.id, '%s, wait please '%message.chat.username)

  1. The first try is not closed
  2. Why call.message?
  3. Curve indentation in a line with if call.data ==
  4. No indentation in if int(message.chat.id) ==
  5. Why get chat id via JSON split? message.chat.id is
  6. Why get text via JSON split?
  7. Does text exist in the message object when it comes to callback?
  8. Why is this try except block needed if the variable from it is not used anywhere?
  9. Why is this try except block needed if the variable from it is not used anywhere?

In general, there are more questions than answers. Your code editor is not all red?

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question