【发布时间】:2022-01-20 17:17:48
【问题描述】:
我已附上代码。我希望从本地机器上的文本文件中访问 chat_id。
#constants.py
chatid_list = []
file1 = open(r'D:\\folder1\\chatids.txt', "r")
for chat_id in file1:
chatid_list.append(chat_id)
#main.py
def start(update, context):
chat_id = update.message.chat_id
first_name =update.message.chat.first_name
last_name = update.message.chat.last_name
username = update.message.chat.username
if chat_id in cp.chatid_list:
print("chat_id : {} and firstname : {} lastname : {} username {}". format(chat_id, first_name, last_name , username))
context.bot.send_message(chat_id, 'Hi ' + first_name + ' Whats up?')
update.message.reply_text( text=main_menu_message(),reply_markup=main_menu_keyboard())
else:
print("WARNING: Unauthorized access denied for {}.".format(chat_id))
update.message.reply_text('User disallowed.')
【问题讨论】:
-
嗨。你到底卡在哪里了?请查看this article 以及 python-telegram-bots ask-right 页面
-
@CallMeStag - 执行 Main.py 文件时。输出始终是用户不允许的。
标签: python-3.x telegram telegram-bot python-telegram-bot