В коде представленный ниже я пытался сделать хендлер отвечающий за мут.
Но что-то пошло не так, помогите пожалуйста.
from aiogram import executor, Bot, Dispatcher, types
import os, sys, time, random, sqlite3
from aiogram.dispatcher.filters import Text, AdminFilter
from aiogram.dispatcher import filters
bot = Bot('My Token')
dp = Dispatcher(bot)
@dp.message_handler(Text(startswith='мут', ignore_case=True))
async def mut(message: types.Message):
user = await bot.get_chat_member(message.chat.id, message.from_user.id)
if user.is_chat_admin():
command = message.text.split()
if len(command) == 3 and command[2].isdigit():
username_mute = command[1].replace('@', '')
chat_member = await bot.get_chat_member(message.chat.id, username_mute)
if chat_member:
# Получаем ID пользователя, которого хотим замутить
user_id_to_mute = chat_member.user.id
# Преобразуем время мута в минутах в секунды
mute_duration_minutes = int(command[2])
mute_duration_seconds = mute_duration_minutes * 60
# Устанавливаем мут на указанное время
await bot.restrict_chat_member(message.chat.id, user_id_to_mute, can_send_messages=False, until_date=mute_duration_seconds)
# Отправляем сообщение об успешном муте
await message.reply(f"Пользователь {username_mute} замучен на {mute_duration_minutes} минут.")
else:
await message.reply("Пользователь с указанным username не найден.")
if __name__ == "__main__":
executor.start_polling(dp, skip_updates=True)
Ошибка:
Task exception was never retrieved
future: <Task finished name='Task-45' coro=<Dispatcher._process_polling_updates() done, defined at F:\python 3.10.5 64bit\lib\site-packages\aiogram\dispatcher\dispatcher.py:407> exception=BadRequest('Invalid user_id
specified')>
Traceback (most recent call last):
File "F:\python 3.10.5 64bit\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 "F:\python 3.10.5 64bit\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 235, in process_updates
return await asyncio.gather(*tasks)
File "F:\python 3.10.5 64bit\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "F:\python 3.10.5 64bit\lib\site-packages\aiogram\dispatcher\dispatcher.py", line 256, in process_update
return await self.message_handlers.notify(update.message)
File "F:\python 3.10.5 64bit\lib\site-packages\aiogram\dispatcher\handler.py", line 117, in notify
response = await handler_obj.handler(*args, **partial_data)
File "f:\Python project\bot (1).py", line 100, in mut
chat_member = await bot.get_chat_member(message.chat.id, username_mute)
File "F:\python 3.10.5 64bit\lib\site-packages\aiogram\bot\bot.py", line 2682, in get_chat_member
result = await self.request(api.Methods.GET_CHAT_MEMBER, payload)
File "F:\python 3.10.5 64bit\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 "F:\python 3.10.5 64bit\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 "F:\python 3.10.5 64bit\lib\site-packages\aiogram\bot\api.py", line 115, in check_result
exceptions.BadRequest.detect(description)
File "F:\python 3.10.5 64bit\lib\site-packages\aiogram\utils\exceptions.py", line 141, in detect
raise cls(description)
aiogram.utils.exceptions.BadRequest: Invalid user_id specified