Need to make a dispatcher filter to execute a code only if message.text has inside a specified command or doesn't have any command.
I have tried this and many others combinations of aiogram 3 F:
@dp.message(F.text and (~(F.entities[...].type == MessageEntityType.BOT_COMMAND) or F.text.startswith("/mycommand")))
but it doesn't work properly.
Any suggestions? How to mix F filter parameters correctly?
from aiogram.filters import Command, or_f
@dp.message(or_f(Command("mycommand"), ~F.text.startswith('/')))
The filter is composed using the or_f function, which combines multiple filters with a logical OR operator. The filters applied are:
Command("mycommand")
: Matches messages that are commands and
specifically starts with "mycommand".~F.text.startswith('/')
:
Matches messages that do not start with a forward slash ("/"),
indicating they are not commands.Overall, this filter is designed to capture messages that either match the command "mycommand" or are not traditional command messages.