P
P
Python Newbie2021-08-24 15:32:23
Python
Python Newbie, 2021-08-24 15:32:23

How to get the username of a user in aiogram?

How to get the username of the user who wrote the command. I want to output it to the console.
I use aiogram

Answer the question

In order to leave comments, you need to log in

3 answer(s)
A
Amigun, 2021-08-24
@Levman5

@dp.message_handler(commands=['start'], state='*')
async def start(msg: types.Message):
    await bot.send_message(msg.from_user.id, msg.from_user.first_name)

A
alexbprofit, 2021-08-24
@alexbprofit

here is the solution

R
Resolut, 2021-08-25
@lxst

message.from_user.username

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question