E
E
Elliot Alderson2019-03-13 20:32:09
Python
Elliot Alderson, 2019-03-13 20:32:09

Trouble writing a Telegram bot in Python?

I welcome everyone! I decided to write a bot for Telegram, to try myself in this area. Here is the code:

import telebot
bot = telebot.TeleBot('токен')

@bot.message_handler(content_types=['text'])
def get_text_messages(message):
    if message.text == "Привет":
        bot.send_message(message.from_user.id, "Привет, я ВЕЛИКИЙ БОТ ВИТАЛИЙ, но ты можешь звать меня Витя, чем я могу тебе помочь?")
    elif message.text == "/help":
        bot.send_message(message.from_user.id, "Напиши привет")
    else:
        bot.send_message(message.from_user.id, "Я тебя не понимаю. Напиши /help.")

bot.polling(none_stop=True, interval=0)

At startup, it gives a bunch of errors related to connecting to the server and the like. The full text with errors is unlikely to fit here. I wanted to ask how to fix this, if anyone knows.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
Ivan Mikhailov, 2019-03-14
@h1tech

I do this (in order not to bother with connecting through a proxy): I upload my script to www.pythonanywhere.com and run it there, after installing the necessary modules. For the test, the free tariff is enough for the eyes. And if you wish, you can then run it using cron

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question