Skip to content
Advertisement

Is it possible with aiogram to know, who sent the message?

So the Telegram Bot can do different actions, depending on who activated the command. This concerns aiogram, a framework for Telegram Bot API

Advertisement

Answer

You could use a simple filtering system:

  1. Create a dict/database with user_id’s and their roles
  2. Get the role from that dict/db by id and do the action

This solution in code:

roles={1234:'Admin', 1243:'User', 1223:'Moderator'}

@dp.message_handler()
async def handler(message: types.Message) -> None:
    role=roles[message.from_user.id]

    if role=='Admin': do_action()
    elif role=='User': do_another_action()
    elif role=='Moderator': do_yet_another_action()

#you can add a check at start, to see if person even has a role
#if message.from_user.id in roles:
User contributions licensed under: CC BY-SA
7 People found this is helpful
Advertisement