M
M
MalekBV2019-08-22 12:11:18
Python
MalekBV, 2019-08-22 12:11:18

Error in telegram bot API, error with keyboard, NameError: name 'types' is not defined?

Here is the code
@bot.message_handler(commands = ['choice'])
def inline(message):
key = types.InlineKeyboardMarkup()
but_1 = types.InlineKeyboardButton(text="Alfredo", callback_data="Alfredo")
but_2 = types. InlineKeyboardButton(text="Celentano", callback_data="Celentano")
key.add(but_1, but_2)
bot.send_message(message.chat.id, "Who is your idol?", reply_markup=key)
@bot.callback_query_handler(func =lambda c:True)
def inlin(c):
if c.data == 'Alfredo':
bot.send_message(c.message.chat.id, 'Yes')
if c.data == 'Celentano':
bot. send_message(c.message.chat.id, 'None')
throws an error:
NameError: name 'types' is not defined
Help with solving the problem

Answer the question

In order to leave comments, you need to log in

2 answer(s)
H
Herr_Konrad, 2019-08-22
@malekBV

Probably forgot to add
from telebot import types

I
Igor, 2019-08-25
@karatel318

In this case, you need to import types from telebot, there are two options, the first is to import only types : The second option is to import all modules from telebot :
from telebot import *

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question