Is there anyway that telegram bot can set commands that is available for administrator only? Because I wanted to implement a function that only admins of the telegram bot can use, not for other users.
- December 21, 2021
- 126 views
- 0 votes
- 2 Answers
-
Is there anyway that telegram bot can set commands that is available for administrator only? Because I wanted to implement a function that only admins of the telegram bot can use, not for other users.
2
Answers
Use a wrapper.
With
python-telegram-bot
there are several ways to do that. A decorator as inyrface suggested can work – see also here and here for a way to cache the admins list. Another option is to userFilters.user
. Finally,ptbcontrib/roles
has a built-in cached admin check.in addition to all of that, you can set up the commands such that in the gui they are only visible to admins – using
BotCommandScopeChatAdministrators
. This doesn’t prevent other users from manually typing the command, but’s an additional step.Disclaimer: I.m currently the maintainer of
python-telegram-bot