Answer the question
In order to leave comments, you need to log in
What is the problem with the telegram API?
I ran into a problem: I run the telegram bot, it doesn’t give any errors, but it doesn’t work, the API key is attached, the whole program code:
import telebot
import config
from time import time
from telebot import types
bot = telebot.TeleBot(config.TOKEN)
GROUP_ID = -1001475859310
strings = {
"ru": {
"ro.msg": "Вам зарпрещено писать в чате в течение 10 минут."
},
"en": {
"ro.msg": "You`re not allowed at this chat for 10 minutes."
}
}
def get_language(lang_code):
if not lang_code:
return "en"
if "-" in lang_code:
lang_code = lang_code.split("-")[0]
if lang_code == "ru":
return "ru"
else:
return "en"
@bot.message_handler(func=lambda message: message.entities is not None and message.chat.id == GROUP_ID)
def delete_links(message):
for entity in message.entities:
if entity.type in ["url", "text_link"]:
bot.delete_message(message.chat.id, message.message_id)
else:
return
resticted_messages = ["i am vegan"]
@bot.message_handler(func=lambda message: message.text and message.text.lower() in resticted_messages and message.chat.id == GROUP_ID)
def set_to(message):
print(message.from_user.language_code)
bot.restict_chat_member(message.chat.id, message.from_user.id, until_date=time()+600)
bot.send_message(message.chat.id, strings.get(get_language(message.from_user.language_code)).get("ro.msg"), reply_to_message_id=message.message_id)
if __name__ == "__main__":
bot.infinity_polling()
@bot.message_handler(commands=['start'])
def welcome(message):
bot.send_message(message.chat.id, "Привет, {0.first_name}!\n Я - бот {1.first_name}. Для просмотра списка моих команд введите '/list'".format(message.from_user, bot.get_me()),
parse_mode='html')
@bot.message_handler(commands=['list'])
def list(message):
bot.send_message(message.chat.id, "Список доступных команд:\n/ban(/kick)-исключить пользователя из беседы\n/test\n/text".format(message.from_user, bot.get_me()),)
@bot.message_handler(content_types=['text'])
def lalala(message):
if message.chat.type == 'private':
if message.text == 'Готово':
bot.send_message(message.chat.id, "Отлично! Мы записали твой Blockchain-кошелек в участников акции! Ожидай подведения результатов РОВНО 1 ИЮНЯ!!!")
else:
bot.send_message(message.chat.id, "Ошибка! Вы не выполняли все условия нашей раздачи!")
#RUN
bot.polling(none_stop=True)
Answer the question
In order to leave comments, you need to log in
Your command handler start
is located after bot.infinity_polling()
, so it is never called.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question