@motionless123

Ошибка при попытке забанить человека в беседе Telegram бота — Python (aiogram)?

import config
import logging
import filters
import asyncio

from contextlib import suppress
from aiogram import Bot, Dispatcher, executor, types
from aiogram.utils.exceptions import (MessageToEditNotFound, MessageCantBeEdited, MessageCantBeDeleted,
                                      MessageToDeleteNotFound)

from filters import AdminFilter

# Log level
logging.basicConfig(level=logging.INFO)

# Bot init
bot = Bot(token=config.TOKEN)
dp = Dispatcher(bot)

# Activate filters
dp.filters_factory.bind(AdminFilter)

# Ban command(admins only)
@dp.message_handler(is_admin=True, commands=['ban'], commands_prefix='!/')
async def cmd_ban(message: types.Message):
    if not message.reply_to_message:
        await message.reply('Данная команда должна быть ответом на сообщение')
        return

    await bot.kick_chat_member(chat_id=config.GROUP_ID, user_id=message.reply_to_message.from_user.id)
    await message.delete()

    await message.reply_to_message.reply("Участник наказан")

# run long-polling
if __name__ == "__main__":
    executor.start_polling(dp, skip_updates=True)


Сама ошибка:
ERROR:asyncio:Task exception was never retrieved
future: <Task finished name='Task-9' coro=<Dispatcher._process_polling_updates() done, defined at D:\Users\Xiney\AppData\Local\Programs\Thonny\lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=BadRequest("Can't ban members in private chats")>
Traceback (most recent call last):
  File "D:\Users\Xiney\AppData\Local\Programs\Thonny\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 415, in _process_polling_updates
    for responses in itertools.chain.from_iterable(await self.process_updates(updates, fast)):
  File "D:\Users\Xiney\AppData\Local\Programs\Thonny\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
    return await asyncio.gather(*tasks)
  File "D:\Users\Xiney\AppData\Local\Programs\Thonny\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "D:\Users\Xiney\AppData\Local\Programs\Thonny\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
    return await self.message_handlers.notify(update.message)
  File "D:\Users\Xiney\AppData\Local\Programs\Thonny\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
    response = await handler_obj.handler(*args, **partial_data)
  File "D:\Python\bot.py", line 30, in cmd_ban
    await bot.kick_chat_member(chat_id=config.GROUP_ID, user_id=message.reply_to_message.from_user.id)
  File "D:\Users\Xiney\AppData\Local\Programs\Thonny\lib\site-packages\aiogram\bot\bot.py", line 1848, in kick_chat_member
    return await self.ban_chat_member(
  File "D:\Users\Xiney\AppData\Local\Programs\Thonny\lib\site-packages\aiogram\bot\bot.py", line 1838, in ban_chat_member
    return await self.request(api.Methods.BAN_CHAT_MEMBER, payload)
  File "D:\Users\Xiney\AppData\Local\Programs\Thonny\lib\site-packages\aiogram\bot\base.py", line 236, in request
    return await api.make_request(await self.get_session(), self.server, self.__token, method, data, files,
  File "D:\Users\Xiney\AppData\Local\Programs\Thonny\lib\site-packages\aiogram\bot\api.py", line 140, in make_request
    return check_result(method, response.content_type, response.status, await response.text())
  File "D:\Users\Xiney\AppData\Local\Programs\Thonny\lib\site-packages\aiogram\bot\api.py", line 115, in check_result
    exceptions.BadRequest.detect(description)
  File "D:\Users\Xiney\AppData\Local\Programs\Thonny\lib\site-packages\aiogram\utils\exceptions.py", line 141, in detect
    raise cls(description)
aiogram.utils.exceptions.BadRequest: Can't ban members in private chats
  • Вопрос задан
  • 65 просмотров
Решения вопроса 1
Lord_of_Rings
@Lord_of_Rings
Python developer
Ошибка при попытке забанить человека в беседе Telegram бота — Python (aiogram)?

Да, ошибка
Ответ написан
Комментировать
Пригласить эксперта
Ваш ответ на вопрос

Войдите, чтобы написать ответ

Войти через центр авторизации
Похожие вопросы