Click here to Skip to main content
15,891,529 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
The buttons do not work in the bot, although the libraries are installed and the types are imported. After adding Inline and reply buttons, it began to crash. 
Here is the code:

import telebot
from telebot import types
import logging
import requests

bot = telebot.TeleBot('ТОКЕН')

keyboard1 = telebot.types.(resize_keyboard = True)
keyboard1.add('Заказать', 'Доставка', 'Скидки и акции', 'Отзыв', 'Support', 'Подарок', 'Мы в Instagram')

#Start
@bot.message_handler(commands=['start'])
def send_welcome(message):
name = message.from_user.first_name
print(name)
bot.reply_to(message, 'Привет,' + name + '!', parse_mode= "Markdown")

#Помощь
@bot.message_handler(commands=['help'])
def start_message(message):
bot.send_message(message.chat.id, 'написать')

#Заказать
@bot.message_handler(commands=['zakaz'])
def start_message(message):
bot.send_message(message.chat.id, 'написать')

#Инстаграм
@bot.message_handler(commands=['Instagram'])
def start_message(message):
bot.send_message(message.chat.id, 'написать')

@bot.message_handler(content_types=['text'])
def send_text(message):
if message.text == 'Заказать':
bot.send_message(message.chat.id, 'Привет, мой создатель')
elif message.text == 'Доставка':
bot.send_message(message.chat.id, 'Прощай, создатель')

@bot.message_handler(commands = ['get_info'])
def get_user_info(message):
markup_inline = types.InlineKeyboardMarkup()
item_yes = types.InlineKeyboardButton(text = 'ДА', callback_data = 'yes')
item_no = types.InlineKeyboardButton(text = 'НЕТ', callback_data= 'no')
markup_inline.add(item_yes, item_no)
bot.send_message(message.chat.id, 'Проверьте правильно ли указана информация?'
reply_markup = markup_inline
)

@bot.callback_query_handler(func = lambda call: True)
def answer(call):
if call.data == 'yes':
markup_reply = types.ReplyKeyboardMarkup(resize_keyboard = True)
item_zakaz = types.KeyboardButton('Заказать')
item_otzuv = types.KeyboardButton ('Отзыв')

markup_reply.add(item_zakaz, item_otzuv)
bot.send_message(call.message.chat.id, 'Выберите что хотите сделать'
reply_markup = markup_reply
)
elif call.data == 'no'
pass
@bot.message_handler(content_types = ['text'])
def get_text(message):
if message.text == 'Заказать':
bot.send_message(message.chat.id, f'Хорошо:'message.from_user.first_name)
elif message.text == 'Заказать':
bot.send_message(message.chat.id, f'Найс:'message.from_user.last_name)

bot.polling(none_stop= True)

    import telebot
    from telebot import types
    import logging
    import requests
    
    bot = telebot.TeleBot('TOKEN')
    
    keyboard1 = telebot.types.(resize_keyboard = True)
    keyboard1.add('Заказать', 'Доставка', 'Скидки и акции', 'Отзыв', 'Support', 'Подарок', 'Мы в Instagram')
    
    #Start
    @bot.message_handler(commands=['start'])
    def send_welcome(message):
    name = message.from_user.first_name
    print(name)
    bot.reply_to(message, 'Привет,' + name + '!', parse_mode= "Markdown")
    
    #Помощь
    @bot.message_handler(commands=['help'])
    def start_message(message):
    bot.send_message(message.chat.id, 'написать')
    
    #Заказать
    @bot.message_handler(commands=['zakaz'])
    def start_message(message):
    bot.send_message(message.chat.id, 'написать')
    
    #Инстаграм
    @bot.message_handler(commands=['Instagram'])
    def start_message(message):
    bot.send_message(message.chat.id, 'написать')
    
    @bot.message_handler(content_types=['text'])
    def send_text(message):
    if message.text == 'Заказать':
    bot.send_message(message.chat.id, 'Привет, мой создатель')
    elif message.text == 'Доставка':
    bot.send_message(message.chat.id, 'Прощай, создатель')
    
    @bot.message_handler(commands = ['get_info'])
    def get_user_info(message):
    markup_inline = types.InlineKeyboardMarkup()
    item_yes = types.InlineKeyboardButton(text = 'ДА', callback_data = 'yes')
    item_no = types.InlineKeyboardButton(text = 'НЕТ', callback_data= 'no')
    markup_inline.add(item_yes, item_no)
    bot.send_message(message.chat.id, 'Проверьте правильно ли указана информация?'
    reply_markup = markup_inline
    )
    
    @bot.callback_query_handler(func = lambda call: True)
    def answer(call):
    if call.data == 'yes':
    markup_reply = types.ReplyKeyboardMarkup(resize_keyboard = True)
    item_zakaz = types.KeyboardButton('Заказать')
    item_otzuv = types.KeyboardButton ('Отзыв')
    
    markup_reply.add(item_zakaz, item_otzuv)
    bot.send_message(call.message.chat.id, 'Выберите что хотите сделать'
    reply_markup = markup_reply
    )
    elif call.data == 'no'
    pass
    @bot.message_handler(content_types = ['text'])
    def get_text(message):
    if message.text == 'Заказать':
    bot.send_message(message.chat.id, f'Хорошо:'message.from_user.first_name)
    elif message.text == 'Заказать':
    bot.send_message(message.chat.id, f'Найс:'message.from_user.last_name)
    
    bot.polling(none_stop= True)


What I have tried:

The buttons do not work in the bot, although the libraries are installed and the types are imported. After adding Inline and reply buttons, it began to crash. 
Posted
Updated 16-Dec-20 15:52pm
Comments
Richard MacCutchan 12-Sep-20 12:33pm    
You need to provide more details. Just dumping your code and expecting someone here to debug it for you is not a good approach.

1 solution

It seems you're missing something in your line
keyboard1 = telebot.types.(resize_keyboard = True)

it should probably look like this
keyboard1 = telebot.types.InlineKeyboardButton(resize_keyboard = True)
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900