T
T
tatsuki12021-09-15 21:31:38
Python
tatsuki1, 2021-09-15 21:31:38

Telegram bot doesn't want to work?

Hello, the last function is not working, the code is below

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: call.data == "phoenix")
def serv(call):
            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
soremix, 2021-09-15
@tatsuki1

Because the first decorator @bot.callback_query_handler(func=lambda call:True)
catches all events with a click on the callback button.
So either take the second function and stuff it into the first, or replace the first with

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

and remove the corresponding checks from the body of the function

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question