Answer the question
In order to leave comments, you need to log in
Bot won't start. how to start?
import telebot
import configure
from telebot import types
bot = telebot.TeleBot('1776373552:AAH4Xf1yOfCa80Lyq3QEkE4EUyMfGauvHBY')
@bot.message_handler(commands=['get_info', 'info'])
def get_user_id(message):
markup_inline = types.InlineKeyboardMarkup()
but_yes = types.InlineKeyboardButton(text='Да', callback_data='yes')
but_no = types.InlineKeyboardButton(text='Нет', callback_data='no')
markup_inline.add(but_yes, but_no)
client.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)
but_ID = types.KeyboardButton('МОЙ ID')
but_username = types.KeyboardButton('МОЙ НИК')
markup_reply.add(but_ID, but_username)
client.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.lower() == 'привет':
client.send_message(message.chat.id, 'Привет, неизвестный юзер!')
elif message.text.lower() == 'как дела?':
client.send_message(message.chat.id, 'Все хорошо, как у тебя?')
@bot.message_handler(content_types=['text'])
def get_text(message):
if message.text() == 'МОЙ ID':
client.send_message(message.chat.id, f'Your ID: {message.from_user.id}')
elif message.text() == 'МОЙ НИК':
client.send_message(message.chat.id, f'Your ID: {message.from_user.first_name}, {message.from_user.last_name}')
bot.polling()
Answer the question
In order to leave comments, you need to log in
Replace client.send_message with bot.send_message and check the token,
my bot @danila763_bot works for me, your code is on it now, I'll keep it running for 15 minutes, check
import telebot
# import configure
from telebot import types
bot = telebot.TeleBot(token)
@bot.message_handler(commands=['get_info', 'info'])
def get_user_id(message):
markup_inline = types.InlineKeyboardMarkup()
but_yes = types.InlineKeyboardButton(text='Да', callback_data='yes')
but_no = types.InlineKeyboardButton(text='Нет', callback_data='no')
markup_inline.add(but_yes, but_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)
but_ID = types.KeyboardButton('МОЙ ID')
but_username = types.KeyboardButton('МОЙ НИК')
markup_reply.add(but_ID, but_username)
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.lower() == 'привет':
bot.send_message(message.chat.id, 'Привет, неизвестный юзер!')
elif message.text.lower() == 'как дела?':
bot.send_message(message.chat.id, 'Все хорошо, как у тебя?')
@bot.message_handler(content_types=['text'])
def get_text(message):
if message.text() == 'МОЙ ID':
bot.send_message(message.chat.id, f'Your ID: {message.from_user.id}')
elif message.text() == 'МОЙ НИК':
bot.send_message(message.chat.id, f'Your ID: {message.from_user.first_name}, {message.from_user.last_name}')
bot.polling()
1. It can't start, as mentioned above - the client variable is not defined
2. Two identical decorators for two functions with the same names must be removed.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question