I am working on a bot in aiogram 3, and when I try to use the built-in set_my_commands command, the bot launch is interrupted with the following errors:
raise validation_error
pydantic.error_wrappers.ValidationError: 1 validation error for BotCommand
description
field required (type=value_error.missing)
Exception ignored in: <function _ProactorBasePipeTransport.__del__ at 0x0424A148>
Traceback (most recent call last):
File "D:\Programs\Python\Python38-32\lib\asyncio\proactor_events.py", line 116, in __del__
File "D:\Programs\Python\Python38-32\lib\asyncio\proactor_events.py", line 108, in close
File "D:\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 711, in call_soon
File "D:\Programs\Python\Python38-32\lib\asyncio\base_events.py", line 504, in _check_closed
RuntimeError: Event loop is closed
Here are code snippets that roughly reflect the essence of what is written in the project (the whole project is too big to cite) :
File commands.py with the location project.core.utils.commands
from aiogram import Bot
from aiogram.types import BotCommand, BotCommandScopeDefault
async def set_commands(bot: Bot):
commands = [BotCommand(command='start', descriptions='Begin work')]
await bot.set_my_commands(commands, BotCommandScopeDefault())
File basic.py with the location core.handlers.basic.py
from aiogram.types import Message
async def get_start(message: Message):
await message.answer(f'Hi {message.from_user.first_name}. Welcome!')
File main.py with the location project.main.py
from aiogram import Bot, Dispatcher
from core.handlers.basic import get_start
import asyncio
from core.settings import settings
from aiogram.filters import Command
from core.utils.commands import set_commands
async def start_bot(bot: Bot):
print('Bot started!')
await set_commands(bot)
async def stop_bot(bot: Bot):
print('Bot stopped!')
async def start():
bot = Bot(token=settings.bots.bot_token, parse_mode='HTML')
dp = Dispatcher()
dp.startup.register(start_bot)
dp.shutdown.register(stop_bot)
dp.message.register(get_start, Command(commands=['start']))
try:
await dp.start_polling(bot)
finally:
await bot.session.close()
if __name__ == "__main__":
asyncio.run(start())
I don't think this code is important in my error, we are specifically interested in set_my_commands.
Some useful information about the error:
await set_commands(bot)
in the start_bot
function. Without it, the bot runs perfectly and there are no warnings and errors.Exception ignored in:
and ending with RuntimeError:
is duplicated 10 times in the terminal.Python 3.8
aiogram 3.0.0.b7
asyncio 3.4.3
aiohttp 3.8.4
Windows 10
Please do not leave links to similar questions unrelated to aiogram, give a concrete example of a solution to my problem, or describe what exactly the error is.
So a list of what I was looking for and tried:
await async io.sleep(0.1)
after the finally:
block.asyncio.run(start())
with various other "similar" versions written on websites.BotCommandScope
there.All of the above options did not affect the performance of the code. I'm probably doing something wrong.
Looks like in your commands.py when you describe commands in list, your BotCommand's argument 'descriptions' should look like 'description' (without 's' letter at the end)
Your log: 1 validation error for BotCommand description field required (type=value_error.missing)
I think that is the reason of error.