How To Limit Access To A Telegram Bot

后端 未结 5 1341
感情败类
感情败类 2020-12-16 12:07

When I send a message to my Telegram Bot, it responses with no problems.

I wanna limit the access such that me and only me can send message to it.

How can I

5条回答
  •  鱼传尺愫
    2020-12-16 12:47

    As this question is related to python-telegram-bot, information below is related to it:

    When you add handlers to your bot's dispatcher, you can specify various pre-built filters (read more at docs, github) or you can create custom ones in order to filter incoming updates.

    To limit access to a specific user, you need to add Filters.user(username="@telegramusername") when initializing handler, e.g.:

    dispatcher.add_handler(CommandHandler("start", text_callback, Filters.user(username="@username")))

    This handler will accept /start command only from user with username @username.

    You can also specify user-id instead of username, which I would highly recommend, as latter is non-constant and can be changed over time.

提交回复
热议问题