S
S
Serov_V2020-01-31 14:12:05
Bots
Serov_V, 2020-01-31 14:12:05

Bot doesn't work when PyCharm is closed and I don't understand what to do?

import telebot
import config
import random
from telebot import types

bot = telebot.TeleBot(config.TOKEN)

@bot.message_handler(commands=['start'])
def welcome(message):

# Keyboard
markup = types.ReplyKeyboardMarkup(resize_keyboard=True )
item1 = types.KeyboardButton("Random number")
item2 = types.KeyboardButton("How are you?")

markup.add(item1, item2 )

# Start
bot.send_message(message.chat.id,'Welcome, ' " {0.first_name}!\n I am {1.first_name} ,"' the bot was created to help newbies'.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?':

markup = types.InlineKeyboardMarkup(row_width=2)
item1 = types.InlineKeyboardButton('Good', callback_data = 'good')
item2 = types.InlineKeyboardButton('Not good ', callback_data='bad')

markup.add(item1, item2)

bot.send_message(message.chat.id, 'Fine, how are you?', reply_markup=markup)
else:
bot.send_message(message.chat.id, 'I don't know what to say')

@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, 'That's great!')
elif call.data == 'bad':
bot.send_message(call.message.chat.id, 'Sometimes')

bot. edit_message_text(chat_id=call.message.chat.id, message_id=call.message.message_id, text='How are you?',
reply_markup=None)

except Exception as e:
print(repr(e))

bot.polling()

Here is the bot code. But the problem is that the bot doesn't work when my pycharm program is closed

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Andrey, 2020-01-31
@anerev

Hacker in the third generation, not running a bot to complain that it does not work

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question