K
K
kirill3472022-01-31 10:10:23
Python
kirill347, 2022-01-31 10:10:23

I'm trying to make a telegram bot, everything seems to be correct, but there are two errors, what's wrong?

import telebot
import config
import random

from telebot import types

bot = telebot.TeleBot(config.TOKEN)

@bot.message_handler(commands=['start'])
def welcome(message):
bot.send_message(message.chat.id, ' Hey, what do you want to know?)')



markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton('Random number')
item2 = types.KeyboardButton('How are you')

markup.add(item1, item2)
bot.send_message(message.chat.id, "Welcome, {0.first_name}! \nI'm {1.first_name} , a bot designed to do something".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 == 'Random number':
bot.send_message(message.chat. id, str(random.randint((0,100))))
elif message.text == 'How are you':
bot.send_message(message.chat.id, 'Great')
else:
bot.send_message(message.chat.id , 'I can't speak yet, but I'm sure I can!)')

bot.polling(none_stop=True)

Here's the code.
When you start, everything is fine, but if you press "how are you" on the keyboard in the telegram, instead of the desired phrase, it answers the classic answer: 'For the time being, I can't speak, but I'll definitely learn!
Secondly, when you press a random number button on the keyboard, the bot breaks and displays this error: bot.send_message(message.chat.id, str(random.randint((0,100))))
TypeError: randint() missing 1 required positional argument: 'b'
Help please how can I solve this?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
soremix, 2022-01-31
@kirill347

At startup, everything is fine, but if you press "how are you" on the keyboard in the telegram, instead of the desired phrase, it answers the classic answer: 'I can't speak yet, but I'll definitely learn!)'.

Mixed Latin and Cyrillic Too many brackets
elif message.text == 'Kак дела':
bot.send_message(message.chat.id, str(random.randint(0,100)))

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question