skip to Main Content

im new to python and now im working to telegram bot using aiogram, i want to make my commands without slashes "/" in front of my commands.

the code i use

@dp.message_handler(commands=["start", 'help'], commands_prefix='/')
async def welcome(message: types.Message):
    await message.reply("Hello! I'm Humann!")

@dp.message_handler()
async def echo(message: types.Message):
    await message.answer(f"you said {message.text}?")

executor.start_polling(dp)

i dont know how to remove slashes, anybody help pleaseπŸ˜‡πŸ™πŸ™. i’ll apreciate it.
thanks

aiogram, fix telegram bot

2

Answers


  1. Im prob. not the best person to answer, as Iv never coded in Py, but
    maybe you can look for how to escape special character, such as /.

    I found this on W3:

    Signals a special sequence (can also be used to escape special
    characters) "d"

    https://www.w3schools.com/python/python_regex.asp

    Maybe d could be helpful for you?

    Login or Signup to reply.
  2. if I understood correctly:

    You want to send text commands without slashes

    you could simply filter messages by text for example, you send to bot

    info

    @dp.message_handler(text='info')
    async def welcome(message: types.Message):
        # you can do something here if user sends text message: info
        await message.answer(f"You send: {message.text}")
    

    bot will answer:

    You send: info

    And this looks like command without slash

    !!! Remember to paste this before all other text-messages handlers, or if you paste it last – your message will go to echo function (because it filters all text messages.


    Aiogram has a lot of variables for commands (CommandStart, CommandSettings)? you should see all in aiogram filters documentation

    Commands is better when you set default_commands in bot and next you could see and use them all when you press menu button (in private chat with bot)

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search