Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/319.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
电报机器人python使用用户id授权用户_Python_Python 3.x_Telegram_Telegram Bot_Python Telegram Bot - Fatal编程技术网

电报机器人python使用用户id授权用户

电报机器人python使用用户id授权用户,python,python-3.x,telegram,telegram-bot,python-telegram-bot,Python,Python 3.x,Telegram,Telegram Bot,Python Telegram Bot,我用允许的用户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

我用允许的用户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,它看起来与我的数组对象相同,但我始终收到消息u不允许运行此bot 请问,有人能解释一下我做错了什么吗?

message.chat.id是整数值,所以您必须使用带整数的列表

users_id = [123213213] 
顺便说一句:你可以检查它的打印和类型

使用printmessage.chat.id和print typemessage.chat.id查看message.chat.id中的内容-只需了解如何调试代码。也许你的身份证总是和123213不一样。或者它给您的对象不同于字符串-可能ID是整数,您应该使用users\u ID=[123213213]
print(message.chat.id, type(message.chat.id))