本文介绍了如何在pyTelegramBotAPI中将访问权限限制为少数用户?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时删除!!

我正在使用Telebot( https://github.com/eternnoir/pyTelegramBotAPI )来创建一个机器人以将照片发送给其用户.关键是我没有打算限制对该机器人的访问,因为我打算通过该机器人共享私有映像.

I'm using telebot (https://github.com/eternnoir/pyTelegramBotAPI) to create a bot to send photos to its users. The point is I didn't see a way to restrict the access to this bot as I intend to share private images through this bot.

我在这个论坛上阅读到,通过python-telegram-bot,有一种方法可以限制发件人消息的访问权限(),但我不知道是否可以通过pyTelegramBotAPI实现.

I read in this forum that through python-telegram-bot there is a way to limit the access from the sender's message (How To Limit Access To A Telegram Bot), but I didn't know if via pyTelegramBotAPI it is possible.

你知道我该怎么解决吗?

Do you know how can I solve it?

推荐答案

最简单的方法可能是对用户ID进行硬编码检查.

The easiest way is probably a hard coded check on the user id.

# The allowed user id
my_user_id = '12345678'

# Handle command
@bot.message_handler(commands=['picture'])
def send_picture(message):

    # Get user id from message
    to_check_id = message.message_id

    if my_user_id = to_check_id:
        response_message = 'Pretty picture'
    else:
        response_message = 'Sorry, this is a private bot!'

    # Send response message
    bot.reply_to(message, response_message)

这篇关于如何在pyTelegramBotAPI中将访问权限限制为少数用户?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

1403页,肝出来的..

09-06 15:44