T
T
tatsuki12021-09-07 16:35:25
Python
tatsuki1, 2021-09-07 16:35:25

Inline button not working?

Hello again. I decided to rewrite to inline keyboard. But there was a problem. Buttons before "if call.data == 'phoenix' " work, after it they don't. I'll attach the code below.
The code:

import telebot
from telebot import types
from config import TOKEN


bot = telebot.TeleBot(TOKEN)

@bot.message_handler(commands=['start'])
def start(message):
    start = types.ReplyKeyboardMarkup(resize_keyboard=True)
    item1 = types.KeyboardButton('Arizona GAMES')

    start.add(item1)

    bot.send_message(message.chat.id, 'Привет, ты попал в личные сообщение с ботом ARIZONA GAMES, для следующий действий используй кнопкни ниже.', reply_markup = start)

@bot.message_handler(content_types=['text'])
def bot_message(message):
    if message.chat.type == 'private':
        if message.text == 'Arizona GAMES':
            arzg = types.InlineKeyboardMarkup()
            arz = types.InlineKeyboardButton('Arizona RP', callback_data='arg')
            rod = types.InlineKeyboardButton('Rodina RP', callback_data='rod')
            jdv = types.InlineKeyboardButton('Жизнь в Деревне', callback_data='jdv')
            arzg.add(arz, rod, jdv)
            bot.send_message(message.chat.id, 'Вы выбрали: Arizona Games', reply_markup=arzg)


@bot.callback_query_handler(func=lambda call:True)
def arzg(call):
    if call.message:
        if call.data == 'arg':
            nazv = types.InlineKeyboardMarkup()
            phoenix = types.InlineKeyboardButton('Phoenix', callback_data='phoenix')
            tucson = types.InlineKeyboardButton('Tucson', callback_data='tucson')
            scottdale = types.InlineKeyboardButton('Scottdale', callback_data='scottdale')
            chandler = types.InlineKeyboardButton('Chandler', callback_data='chandler')
            brainburg = types.InlineKeyboardButton('Brainburg', callback_data='brainburg')
            saintrose = types.InlineKeyboardButton('Saint Rose', callback_data='saintrose')
            mesa = types.InlineKeyboardButton('Mesa',callback_data='mesa')
            redrock = types.InlineKeyboardButton('Red Rock',callback_data='redrock')
            yuma = types.InlineKeyboardButton('Yuma',callback_data='yuma')
            surprise = types.InlineKeyboardButton('Surprise', callback_data='surprise')
            prescott = types.InlineKeyboardButton('Prescott',callback_data='prescott')
            glendale = types.InlineKeyboardButton('Glendale',callback_data='glendale')
            kingman = types.InlineKeyboardButton('Kingman',callback_data='kingman')
            winslow = types.InlineKeyboardButton('Winslow', callback_data='winslow')
            payson = types.InlineKeyboardButton('Payson', callback_data='payson')
            gilbert = types.InlineKeyboardButton('Gilbert', callback_data='gilbert')
            showlow = types.InlineKeyboardButton('Show-Low', callback_data='showlow')
            nazv.add(phoenix,tucson,scottdale,chandler,brainburg,saintrose,mesa,redrock,yuma,surprise,prescott,glendale,kingman,winslow,payson,gilbert,showlow)
            bot.send_message(call.message.chat.id, 'Выберите сервер по которому хотите информацию.', reply_markup=nazv)

@bot.callback_query_handler(func=lambda call:True)
def serv(call):
    if call.message:
        if call.data == 'phoenix':
            phoenix1 = types.InlineKeyboardMarkup()
            vk = types.InlineKeyboardButton('Вконтакте', url='https://vk.com/arizona1phoenix')
            discord = types.InlineKeyboardButton('Дискорд', url='https://discord.gg/rpfXy3t')
            forum = types.InlineKeyboardButton('Раздел форума', url='https://forum.arizona-rp.com/forums/338/')
            phoenix1.add(vk,discord,forum)
            bot.send_message(call.message.chat.id,'Выбрано: Phoenix', reply_markup=phoenix1)


bot.polling(none_stop=True)

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Stefan, 2021-09-07
@tatsuki1

So because your callback gets into the first callback processing function (arzg) and it is processed, naturally it does not reach the other one, process it explicitly, you have callback_query_handler for this

@bot.callback_query_handler(func=lambda call: call.data == "pheonix")

PS: And my God, rewrite the code, create a list of tuples with the desired values, and create buttons in a loop, and not this perversion as you do, and take it into a separate function, and get a keyboard from it,

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question