A
A
Arthur2021-06-22 13:02:17
Python
Arthur, 2021-06-22 13:02:17

Bot not responding to commands?

The video on which I did it CLICK
Here is the code:

import telebot
from telebot import types

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

@bot.message_handler(content_types=['text'])
def ttt(message):

    markup = types.ReplykeyboardMarkup(resize_keyboard=True)

    but1 = types.KeyboardButton("1")
    but2 = types.KeyboardButton("2")
    markup.add(but1, but2)
    if message.text == "1":
        bot.send_message(message.chat.id, "1")
    elif message.text == "2":
        bot.send_message(message.chat.id, "2")

bot.polling(none_stop=True)


In the bot I click on start 0 reactions + the keyboard does not appear

Answer the question

In order to leave comments, you need to log in

3 answer(s)
R
Ronald McDonald, 2021-06-22
@Zoominger

And what should be the reaction? Your click is not processed anywhere and the function is not used.

O
o5a, 2021-06-22
@o5a

Because it is a handler for the text that has already arrived ("BONUS", etc.). And the buttons need to be inserted into the / start command handler

@bot.message_handler(commands=['start'])
def start(message):
    markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
    butt_1 = types.KeyboardButton("ПОЛУЧИТЬ ДЕНЬГИ")
    butt_2 = types.KeyboardButton("БОНУС")
    markup.add(butt_1, butt_2)

    bot.send_message(message.chat.id, "Чё надо?", reply_markup=markup)

A
artur_agishev, 2021-06-23
@artur_agishev

open cmd
go to the project directory, i.e. write cd C:\project_folder
run the python file, i.e. write bot.py

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question