[英]telegram bot python authorize user using user_id
我聲明了一個具有允許的用戶 ID 的數組
users_id = ['123213213']
並嘗試驗證用戶
@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'
)
我打印了message.from_user.id
,它看起來與我的數組 object 相同,但我總是收到消息“你不允許運行這個機器人”,有人能解釋一下我做錯了什么嗎?
message.chat.id
是 integer 值,因此您必須使用帶有整數的列表
users_id = [123213213]
順便說一句:您可以使用print()
和type()
檢查它
print(message.chat.id, type(message.chat.id))
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.