Search code examples
pythonpython-3.xtelegramtelegram-botpython-telegram-bot

telegram bot python authorize user using user_id


I declared an array with permitted user id

users_id = ['123213213'] 

and trying to validate user

@bot.message_handler(commands=['authorize'])
def start_command(message):
    if message.from_user.id not in users_id:
        bot.send_message(
            message.chat.id,
            'u are not permitted to run this bot'
        )
    else:
        bot.send_message(
            message.chat.id,
            'u are welcome'
        )

I printed message.from_user.id and it looks the same as my array object, but i always get message "u are not permitted to run this bot" please, could somebody explain what am i doing wrong?


Solution

  • message.chat.id is integer value so you have to use list with integers

    users_id = [123213213] 
    

    BTW: you can check it with print() and type()

    print(message.chat.id, type(message.chat.id))