axel
axel

Reputation: 4127

How to exclude the /command from message_handler in the dispatcher of Aiogram?

I've a message handler that respond to a command in a Bot application written in python3 with the library Aiogram.

I can receive from the application the message I send to the BOT, but I would like to exclude the command (via config possibly, not parsing the string). Maybe it is in the documentation, but currently I could not find the answer.

To be clear with an example, if I type to my TelegramBot

/my_command text

where this is my code in the python3 application

@dispatcher.message_handler(commands=['my_command'])
async def echo(message: types.Message):

I would like to receive from the message_handler in the message types.Message variable the string text and not /my_command text.

Thanks a lot

Upvotes: 4

Views: 10198

Answers (1)

axel
axel

Reputation: 4127

The function to extract only the arguments of a command is get_args():

@dispatcher.message_handler(commands=['my_command'])
async def echo(message: types.Message):
    arguments = message.get_args()
    await message.reply(arguments)

Upvotes: 7

Related Questions