tucnak / telebot

Telebot is a Telegram bot framework in Go.
MIT License
3.95k stars 461 forks source link

Get username by user id #672

Closed hlee4real closed 1 month ago

hlee4real commented 6 months ago

I want to get username by user id

Here are what I'm trying to use:

b.Handle("/check", func(c tele.Context) error {
        fmt.Println(c.Sender().ID)
        u := &tele.User{ID: 123}
        fmt.Println(u.Username)
        return nil
    })
codeheroo commented 3 months ago

As far as I know, you can't get username by user id. You should store username with user id somewhere if you want to get username by user id.

Wenw97 commented 2 months ago

chat, err := b.ChatByID(893817263) if err != nil { fmt.Println(err) } fmt.Print("username:",chat.Username)