[Python] How can I get user's message and put it into a variable in bot Telethon?

Discussão em 'Python' iniciado por Stack, Maio 11, 2025.

  1. Stack

    Stack Membro Participativo

    I'm making telegram bot using Telethon and I want bot to request users's name (not username or first_name; it's like nickname which user can make by himself). And then bot whill use this name.

    For example, I want bot to call me 'Marshmellow' and bot will do it.

    I want to use inline buttons to do this (so user can always change their name).

    P.S. English is not my first language, so I'm sorry for mistakes.

    I make this:

    @bot.on(events.NewMessage(func=lambda e: e.text.startswith("name: ")))
    async def add_question (event):
    name = event.text[len("name: "):]
    await event.respond(f'This is your name: {name}')


    but name is not global, so I can't use it everywhere. After all, I don't want to use any patterns ("name: ..."). I want to click the button, and just enter my name whitthout 'codes'.

    Continue reading...

Compartilhe esta Página