R
R
Remasten2020-05-13 20:30:05
Python
Remasten, 2020-05-13 20:30:05

Who can help telegram bot?

Hello, I ran into a problem, when sending a message "i am vegan", the bot does not block the user (does not issue a mut) and does not delete links, what could be the problem? The entire code of the program:

import telebot
import config

from time import time 
from telebot import types

bot = telebot.TeleBot(config.TOKEN)

GROUP_ID = -409373889

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)


@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, "Ошибка! Вы не выполняли все условия нашей раздачи!")


bot.polling(none_stop=True)


Ignore the last lines (where: "Error...").
I also want to set up commands to ban users / kick and so on.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question