-1

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?

  • use `print(message.chat.id)` and `print( type(message.chat.id) )` to see what you get in `message.chat.id` - simply learn how to debug code. Maybe you always have ID different then `'123213213`. OR it gives you object different then string - maybe ID is integer and you should use `users_id = [123213213]` – furas Dec 16 '20 at 02:19

1 Answers1

1

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))
furas
  • 134,197
  • 12
  • 106
  • 148