Mail.ruПочтаМой МирОдноклассникиВКонтактеИгрыЗнакомстваНовостиКалендарьОблакоЗаметкиВсе проекты

Как к def callback_inline(call): присвоить message чтоб не было ошибки NameError: name 'message' is not defined

Я хОчУ КаКаЦ Ученик (141), на голосовании 1 год назад
Вот код

import telebot
from telebot import types

bot = telebot.TeleBot('5934808889:AAFNWsZRCHJvHXPubarGJY0DqYVBPjvNG_M')

@bot.message_handler(commands=['start'])

def start(message):
markup1 = types.InlineKeyboardMarkup(row_width=2)
btn1 = types.InlineKeyboardButton('Пивет', callback_data='good')
btn2 = types.InlineKeyboardButton('Пока', callback_data='bad')
markup1.add(btn1, btn2)
bot.send_message(message.chat.id, "Пивет курсед", reply_markup=markup1)


@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
if call.message:
if call.data == 'good':
markup2 = types.InlineKeyboardMarkup(row_width=2)
btn3 = types.InlineKeyboardButton('давай', callback_data='yes')
btn4 = types.InlineKeyboardButton('нет', callback_data='no')
markup2.add(btn3, btn4)
bot.send_message(call.message.chat.id, 'го дружить?', reply_markup=markup2)
elif call.data == 'yes':
bot.send_message(message.chat.id, 'А я не хочу!!')
elif call.data == 'no':
bot.send_message(call.message.chat.id, 'Ну и ладна')
elif call.data == 'bad':
bot.send_message(call.message.chat.id, 'Ну и ладна')

bot.polling(none_stop=True)
Голосование за лучший ответ
Петр Петрович Мастер (1053) 1 год назад
import telebot
from telebot import types

bot = telebot.TeleBot('5934808889:AAFNWsZRCHJvHXPubarGJY0DqYVBPjvNG_M')

@bot.message_handler(commands=['start'])
def start(message):
markup1 = types.InlineKeyboardMarkup(row_width=2)
btn1 = types.InlineKeyboardButton('Hello', callback_data='good')
btn2 = types.InlineKeyboardButton('Goodbye', callback_data='bad')
markup1.add(btn1, btn2)
bot.send_message(message.chat.id, "Hello there!", reply_markup=markup1)

@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
if call.message:
if call.data == 'good':
markup2 = types.InlineKeyboardMarkup(row_width=2)
btn3 = types.InlineKeyboardButton('Yes', callback_data='yes')
btn4 = types.InlineKeyboardButton('No', callback_data='no')
markup2.add(btn3, btn4)
bot.send_message(call.message.chat.id, 'Would you like to be friends?', reply_markup=markup2)
elif call.data == 'yes':
bot.send_message(call.message.chat.id, "I don't want to be friends!")
elif call.data == 'no':
bot.send_message(call.message.chat.id, 'Alright then')
elif call.data == 'bad':
bot.send_message(call.message.chat.id, 'Alright then')

bot.polling(none_stop=True)
Я хОчУ КаКаЦУченик (141) 1 год назад
Thank you или спасибо
Похожие вопросы