skip to Main Content

The name comes out as none. Can someone please help

def funtion_example(update, context):
    #name of the bot user
    chat_user_client = update.message.from_user.username
    update.message.reply_text(str(chat_user_client))

2

Answers


  1. If you look at the bot api docs you will see that only first_name, id and is_bot are not marked as Optional.

    Thus a number of users will not have a username, which you have to take into account and work around.

    Login or Signup to reply.
  2. if you are retriving message from channel you can try sender_chat, in this you will have username of channels and real users, instead in the from_user you will find username of real users and bot. So you need to choose which one use depending of the use-case.

    def funtion_example(update, context):
        #name of the bot user
        chat_user_client = update.message.sender_chat.username
        update.message.reply_text(str(chat_user_client))
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search