Telegram Bot Закрывается не доработов до конца
18.03.2020, 23:04. Показов 581. Ответов 1
Пишу слово /start все cmd сразу закрывается...
Python | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| import telebot
import random
from telebot import types
bot = telebot.TeleBot('мой токен');
@bot.message_handler(commands=['start'])
def welcome(message):
sti = open('static/welcome.webp', 'rb')
bot.send_sticker(message.chat.id, sti)
# keyboard
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton(" Рандомное число")
item2 = types.KeyboardButton(" Как дела?")
markup.add(item1, item2)
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, str(random.randint(0,100)))
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)
bot.send_message(message.chat.id, 'Отлично, сам как?', reply_markup=markup)
else:
bot.send_message(message.chat.id, 'Я не знаю что ответить ')
@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, 'Бывает ')
# remove inline buttons
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text=" Как дела?",
reply_markup=None)
# show alert
bot.answer_callback_query(callback_query_id=call.id, show_alert=False,
text="ЭТО ТЕСТОВОЕ УВЕДОМЛЕНИЕ!!11")
except Exception as e:
print(repr(e))
# RUN
bot.polling(none_stop=True) |
|
Добавлено через 5 минут
Пишу слово /start все cmd сразу закрывается...
Python | 1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
| import telebot
import random
from telebot import types
bot = telebot.TeleBot('мой токен');
@bot.message_handler(commands=['start'])
def welcome(message):
sti = open('static/welcome.webp', 'rb')
bot.send_sticker(message.chat.id, sti)
# keyboard
markup = types.ReplyKeyboardMarkup(resize_keyboard=True)
item1 = types.KeyboardButton("Рандомное число")
item2 = types.KeyboardButton("Как дела?")
markup.add(item1, item2)
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, str(random.randint(0,100)))
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)
bot.send_message(message.chat.id, 'Отлично, сам как?', reply_markup=markup)
else:
bot.send_message(message.chat.id, 'Я не знаю что ответить')
@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, 'Бывает')
# remove inline buttons
bot.edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text="Как дела?",
reply_markup=None)
# show alert
bot.answer_callback_query(callback_query_id=call.id, show_alert=False,
text="ЭТО ТЕСТОВОЕ УВЕДОМЛЕНИЕ!!11")
except Exception as e:
print(repr(e))
# RUN
bot.polling(none_stop=True) |
|
0
|