import telebot
bot = telebot.TeleBot('YOUR_BOT_TOKEN')
@bot.message_handler(commands=['ban'])
def ban_user(message):
# Получаем username из команды
username = message.text.split()[1] # Предполагается, что команда выглядит как /ban @username
chat_id = message.chat.id
# Получаем информацию о пользователе
user_info = bot.get_chat_member(chat_id, username)
if user_info:
user_id = user_info.user.id
# Теперь можно заблокировать пользователя
bot.ban_chat_member(chat_id, user_id)
bot.send_message(chat_id, f'Пользователь {username} был заблокирован.')
else:
bot.send_message(chat_id, 'Пользователь не найден.')
bot.polling()