Ошибка с markup == types.KeyboardsMarkup(resize_keyboard=True) при создании бота
Создаваю свеого первого бота в телеграмме через пайтон. Решил добавить inline keyboard, но код перестал работать и выдает ошибку: markup == types.KeyboardsMarkup(resize_keyboard=True) ^ SyntaxError: invalid character in identifier Не могу разобраться так как опыта мало. Помогите Код:
import telebot
import config
from telebot import types
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(commands=['start'])
def welcome(message):
#keyboard
markup == types.KeyboardsMarkup(resize_keyboard=True)
item1 = types.KeyboardButton("Понедельник")
item2 = types.KeyboardButton("Вторник")
item3 = types.KeyboardButton("Среда")
item4 = types.KeyboardButton("Четверг")
item5 = types.KeyboardButton("Пятница")
item6 = types.KeyboardButton("Суббота")
item7 = types.KeyboardButton("Перемены")
item8 = types.KeyboardButton("Сведение")
markup.add(item1, item2, item3, item4, item5, item6, item7, item8)
bot.send_message(message.chat.id, "Салам, {0.first_name}!\nЯ - <b>{1.first_name}</b>, бот созданный ,чтобы был.".format(message.from_user, bot.get_me()),
parse_mode='html', reply_markup=markup)
@bot.message_handler(content_types=['text'])
def lalala(message):
if message.chat.type == 'private':
if message.text == 'Понедельник':
bot.send_message(message.chat.id,'Пока неизвестно')
if message.text == 'Вторник':
bot.send_message(message.chat.id,'Пока неизвестно')
if message.text == 'Среда':
bot.send_message(message.chat.id,u'ОРЭГ \nФизра \nСтатистика')
if message.text == 'Четверг':
bot.send_message(message.chat.id,u'Программирование \nБух.учёт \nИРиВС')
if message.text == 'Пятница':
bot.send_message(message.chat.id,u'Инструментальные средства \nКомпьютерная графика \nФизра')
if message.text == 'Суббота':
bot.send_message(message.chat.id,'Пока неизвестно')
if message.text == 'Перемены':
bot.send_message(message.chat.id,u'1 пара 8:00-9:20 \n2 пара 9:30-10:50 \n3 пара 11:00-12:20 \n4 пара 12:40-14:00')
elif message.text == 'Сведение':
markup = types.InlineKeyboardMarkup(row_width=2)
item1 = types.InlineKeyboardButton("Список", callback_data='good')
item2 = types.InlineKeyboardButton("Данные", callback_data='bad')
markup.add(item1, item2)
def callback_inline(call):
try:
if call.message:
if call.data == 'good':
bot.send_message(call.message.chat.id, 'информация')
elif call.data == 'bad':
bot.send_message(call.message.chat.id, 'информация')
# RUN
bot.polling(none_stop=True)
Ответы (2 шт):
Автор решения: Maxim Chyorny
→ Ссылка
Вам необходимо просто заместо markup == types.KeyboardsMarkup(resize_keyboard=True) написать markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
В итоге должно получиться так:
import telebot
import config
from telebot import types
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(commands=['start'])
def welcome(message):
#keyboard
markup = types.ReplyKeyboardMarkup(resize_keyboard=True) # <--- тут ошибка, вы сравниваете, а не присваиваете переменной `markup` сам тип клавиатуры, также вы и тип клавиатуры неправильный написали
item1 = types.KeyboardButton("Понедельник")
item2 = types.KeyboardButton("Вторник")
item3 = types.KeyboardButton("Среда")
item4 = types.KeyboardButton("Четверг")
item5 = types.KeyboardButton("Пятница")
item6 = types.KeyboardButton("Суббота")
item7 = types.KeyboardButton("Перемены")
item8 = types.KeyboardButton("Сведение")
markup.add(item1, item2, item3, item4, item5, item6, item7, item8)
bot.send_message(message.chat.id, "Салам, {0.first_name}!\nЯ - <b>{1.first_name}</b>, бот созданный ,чтобы был.".format(message.from_user, bot.get_me()),
parse_mode='html', reply_markup=markup)
@bot.message_handler(content_types=['text'])
def lalala(message):
if message.chat.type == 'private':
if message.text == 'Понедельник':
bot.send_message(message.chat.id,'Пока неизвестно')
if message.text == 'Вторник':
bot.send_message(message.chat.id,'Пока неизвестно')
if message.text == 'Среда':
bot.send_message(message.chat.id,u'ОРЭГ \nФизра \nСтатистика')
if message.text == 'Четверг':
bot.send_message(message.chat.id,u'Программирование \nБух.учёт \nИРиВС')
if message.text == 'Пятница':
bot.send_message(message.chat.id,u'Инструментальные средства \nКомпьютерная графика \nФизра')
if message.text == 'Суббота':
bot.send_message(message.chat.id,'Пока неизвестно')
if message.text == 'Перемены':
bot.send_message(message.chat.id,u'1 пара 8:00-9:20 \n2 пара 9:30-10:50 \n3 пара 11:00-12:20 \n4 пара 12:40-14:00')
elif message.text == 'Сведение':
markup = types.InlineKeyboardMarkup(row_width=2)
item1 = types.InlineKeyboardButton("Список", callback_data='good')
item2 = types.InlineKeyboardButton("Данные", callback_data='bad')
markup.add(item1, item2)
def callback_inline(call):
try:
if call.message:
if call.data == 'good':
bot.send_message(call.message.chat.id, 'информация')
elif call.data == 'bad':
bot.send_message(call.message.chat.id, 'информация')
# RUN
bot.polling(none_stop=True)
Автор решения: user498232
→ Ссылка
import telebot
import config
from telebot import types
bot = telebot.TeleBot(config.TOKEN)
@bot.message_handler(commands=['start'])
def welcome(message):
# keyboard
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton("Понедельник")
item2 = types.KeyboardButton("Вторник")
item3 = types.KeyboardButton("Среда")
item4 = types.KeyboardButton("Четверг")
item5 = types.KeyboardButton("Пятница")
item6 = types.KeyboardButton("Суббота")
item7 = types.KeyboardButton("Перемены")
item8 = types.KeyboardButton("Сведение")
markup.add(item1, item2, item3, item4, item5, item6, item7, item8)
bot.send_message(message.chat.id,
"Hi, {0.first_name}!\nЯ - <b>{1.first_name}</b>, бот-дневник".format(
message.from_user, bot.get_me()),
parse_mode='html', reply_markup=markup)
@bot.message_handler(content_types=['text'])
def lalala(message):
if message.chat.type == 'private':
if message.text == 'Понедельник':
bot.send_message(message.chat.id, 'Пока неизвестно')
if message.text == 'Вторник':
bot.send_message(message.chat.id, 'Пока неизвестно')
if message.text == 'Среда':
bot.send_message(message.chat.id, u'ОРЭГ \nФизра \nСтатистика')
if message.text == 'Четверг':
bot.send_message(message.chat.id, u'Программирование \nБух.учёт \nИРиВС')
if message.text == 'Пятница':
bot.send_message(message.chat.id, u'Инструментальные средства \nКомпьютерная графика \nФизра')
if message.text == 'Суббота':
bot.send_message(message.chat.id, 'Пока неизвестно')
if message.text == 'Перемены':
bot.send_message(message.chat.id,
u'1 пара 8:00-9:20 \n2 пара 9:30-10:50 \n3 пара 11:00-12:20 \n4 пара 12:40-14:00')
elif message.text == 'Сведение':
markup = types.InlineKeyboardMarkup(row_width=2)
item1 = types.InlineKeyboardButton("Список", callback_data='good')
item2 = types.InlineKeyboardButton("Данные", callback_data='bad')
item3 = types.InlineKeyboardButton("Выход", callback_data='exit')
markup.add(item1, item2, item3)
bot.send_message(message.chat.id, "?", reply_markup=markup)
@bot.callback_query_handler(func=lambda call: True)
def callback_inline(call):
try:
if call.message:
if call.data == 'good':
bot.send_message(call.message.chat.id, 'заполните список')
elif call.data == 'bad':
bot.send_message(call.message.chat.id, 'внесите данные')
else:
bot.edit_message_text("выход", call.message.chat.id, call.message.message_id, reply_markup=None)
except:
pass
# RUN
bot.polling(none_stop=True)