python-3.x - 限制访问电报机器人的问题
问题描述
我对python真的很陌生,我希望我的机器人回答只通过用户名限制用户。我正在尝试编写此功能,但我的机器人仅发送一条消息“未授权”。
怎么了?
number_list.append(choice)
if update.effective_user.username not in ["username"]:
query.edit_message_text(text="Not authorized")
return
解决方案
您可以使用 Telebot api
import telebot
bot = telebot.TeleBot("TOKEN")
username = ["USERNAME"]
@bot.message_handler(content_types=["text"])
def default_test(message):
if message.from_user.username not in username:
bot.send_message(message.chat.id, "Not authorized")
else:
bot.send_message(message.chat.id, "Authorized")
bot.polling(none_stop=True)
推荐阅读
- javascript - Javascript 传播与继承
- php - 如何在 cakephp 3.6 中从一个表中选择所有记录和从另一个表中选择一些记录
- angular - 在Angular中使用选择时如何仅显示产品活动= 0
- laravel - 如何更改网站的基本 URL - Laravel 5.4
- python - 根据另一个 DataFrame 选择一个 DataFrame 的列
- java - Hibernate 合并在更新前执行 11000 次选择
- javascript - 电子邮件通知:TypeError:在对象 1 中找不到函数 getColumn
- android - Android,有没有办法在应用程序内更新 Fabric Beta 分布式应用程序?
- powershell - 使用 foreach 循环重命名文件夹匹配模式
- apache-spark - 为什么 _spark_metadata 的所有 parquet 分区文件都在 0 内,但集群有 2 个工作人员?