电报机器人 python 使用 user_id 授权用户
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
,它看起来和我的数组对象一样,但我总是收到消息“你不被允许 运行 这个机器人”
拜托,有人可以解释我做错了什么吗?
message.chat.id
是整数值所以你必须使用整数列表
users_id = [123213213]
顺便说一句: 你可以用 print()
和 type()
检查一下
print(message.chat.id, type(message.chat.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
,它看起来和我的数组对象一样,但我总是收到消息“你不被允许 运行 这个机器人”
拜托,有人可以解释我做错了什么吗?
message.chat.id
是整数值所以你必须使用整数列表
users_id = [123213213]
顺便说一句: 你可以用 print()
和 type()
print(message.chat.id, type(message.chat.id))