Telegram-bot user control

不羁的心 提交于 2019-12-23 17:27:06

问题


I want to create a telegram bot for a home project and i wish the bot only talk to 3 people, how can I do this? I thought to create a file with the chat id of each of us and check it before responding to any command, I think it will work. the bot will send the correct info if it's one of us and "goodbye" to any other

But is there any other way to block any other conversation with my bot?

Pd: I'm using python-telegram-bot


回答1:


For the first part of your question you can make a private group and add your bot as one of its administrators. Then it can talk to the members and answer to their commands.

Even if you don't want to do so, it is possible by checking the chatID of each update that the bot receives. If the chatID exists in the file, DataBase or even in a simple array the bot answers the command and if not it just ignores or sends a simple text like what you said good-bye.

Note that bots cannot block people they can only ignore their messages.



来源:https://stackoverflow.com/questions/43240152/telegram-bot-user-control

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!